Skip to end of metadata
Go to start of metadata
Description

Returns the given date as a string, formatted according to a pattern. The pattern is a format that is full of various placeholders that will display different parts of the date. These are case-sensitive! These placeholders can be repeated for a different effect. For example, M will give you 1-12, MM will give you 01-12, MMM will give you Jan-Dec, MMMM will give you January-December.

 The placeholders are:

SymbolDescriptionPresentationExamplesOther Notes
GEra designatorTextG=AD 
yYearYearyyyy=1996; yy=96Lowercase y is the most commonly used year symbol
YWeek yearYearYYYY=2009; YY=09Capital Y gives the year based on weeks (ie. changes to the new year up to a week early)
MMonth in yearMonthMMMM=July; MMM=Jul; MM=07 
wWeek in yearNumber27If Dec31 is mid-week, it will be in week 1 of the next year
WWeek in monthNumber2 
DDay in yearNumber189 
dDay in monthNumber10 
FDay of week in monthNumber22nd Sunday of the month
EDay name in weekTextEEEE=Tuesday; E=Tue 
uDay number of weekNumber1(1 = Monday, ..., 7 = Sunday)
aAm/Pm markerTextPM 
HHour in day (0-23)Number0 
hHour in am/pm (1-12)Number12  
kHour in day (1-24)Number24 
KHour in am/pm (0-11)Number0 
mMinute in hourNumber30 
sSecond in minuteNumber55 
SMillisecondNumber978 
zTime zoneGeneral time zonezzzz=Pacific Standard Time; z=PST 
ZTime zoneRFC 822 time zoneZ=-0800 
XTime zoneISO 8601 time zoneX=-08; XX=-0800; XXX=-08:00 

 

 

Expert Tip: This function uses the Java class java.text.SimpleDateFormat internally, and will accept any valid format string for that class.

Syntax

system.date.format(date, format)

  • Parameters

Date dateThe date to format.

String format - A format string such as "yyyy-MM-dd HH:mm:ss".

  • Returns

String - A string representing the formatted datetime

  • Scope

All

 

Code Examples
Code Snippet
#This example would format the current date to look like "01/01/01"
 
today = system.date.now()
print system.date.format(today, "yy/MM/dd") #This printed 16/04/01
Code Snippet
#This example would format the current date to look like "2001-01-31 16:59:59"
#This is a standard format that all databases recognize.
 
today = system.date.now()
print system.date.format(today, "yyyy-MM-dd HH:mm:ss")
  • No labels