Newer Version Available
Datetime Class
Namespace
Usage
For more information about the Datetime, see Datetime Data Type.
Datetime Methods
The following are methods for Datetime.
date()
Signature
public Date date()
Return Value
Type: Date
Example
dateGMT()
Signature
public Date dateGMT()
Return Value
Type: Date
Example
day()
Signature
public Integer day()
Return Value
Type: Integer
Example
dayGmt()
Signature
public Integer dayGmt()
Return Value
Type: Integer
Example
dayOfYear()
Signature
public Integer dayOfYear()
Return Value
Type: Integer
Example
For example, February 5, 2008 08:30:12 would be day 36.
dayOfYearGmt()
Signature
public Integer dayOfYearGmt()
Return Value
Type: Integer
Example
format()
Signature
public String format()
Return Value
Type: String
Example
format(dateFormatString)
Signature
public String format(String dateFormatString)
Parameters
- dateFormatString
- Type: String
Return Value
Type: String
Usage
For more information on the Java simple date format, see Java SimpleDateFormat.
Example
format(dateFormatString, timezone)
Signature
public String format(String dateFormatString, String timezone)
Parameters
- dateFormatString
- Type: String
- timezone
- Type: String
- Valid time zone values for the timezone argument are the time zones of the Java TimeZone class that correspond to the time zones returned by the TimeZone.getAvailableIDs method in Java. We recommend you use full time zone names, not the three-letter abbreviations.
Return Value
Type: String
Usage
For more information on the Java simple date format, see Java SimpleDateFormat.
Example
formatGmt(dateFormatString)
Signature
public String formatGmt(String dateFormatString)
Parameters
- dateFormatString
- Type: String
Return Value
Type: String
Usage
For more information on the Java simple date format, see Java SimpleDateFormat.
Example
formatLong()
Signature
public String formatLong()
Return Value
Type: String
Example
getTime()
Signature
public Long getTime()
Return Value
Type: Long
Example
hour()
Signature
public Integer hour()
Return Value
Type: Integer
Example
hourGmt()
Signature
public Integer hourGmt()
Return Value
Type: Integer
Example
millisecond()
Signature
public Integer millisecond()
Return Value
Type: Integer
Example
millisecondGmt()
Signature
public Integer millisecondGmt()
Return Value
Type: Integer
Example
minute()
Signature
public Integer minute()
Return Value
Type: Integer
Example
minuteGmt()
Signature
public Integer minuteGmt()
Return Value
Type: Integer
Example
month()
Signature
public Integer month()
Return Value
Type: Integer
Example
monthGmt()
Signature
public Integer monthGmt()
Return Value
Type: Integer
Example
newInstance(milliseconds)
Signature
public static Datetime newInstance(Long milliseconds)
Parameters
- milliseconds
- Type: Long
Example
newInstance(year, month, day)
Signature
public static Datetime newInstance(Integer year, Integer month, Integer day)
Example
newInstance(year, month, day, hour, minute, second)
Signature
public static Datetime newInstance(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second)
Parameters
Example
newInstanceGmt(year, month, date)
Signature
public static Datetime newInstanceGmt(Integer year, Integer month, Integer date)
Return Value
Type: Datetime
Example
newInstanceGmt(year, month, date, hour, minute, second)
Signature
public static Datetime newInstanceGmt(Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second)
Parameters
Return Value
Type: Datetime
Example
now()
Signature
public static Datetime now()
Example
parse(datetimeString)
Signature
public static Datetime parse(String datetimeString)
Parameters
- datetimeString
- Type: String
Example
second()
Signature
public Integer second()
Return Value
Type: Integer
Example
secondGmt()
Signature
public Integer secondGmt()
Return Value
Type: Integer
Example
time()
Signature
public Time time()
Return Value
Type: Time
Example
timeGmt()
Signature
public Time timeGmt()
Return Value
Type: Time
Example
valueOf(dateTimeString)
Signature
public static Datetime valueOf(String dateTimeString)
Parameters
- dateTimeString
- Type: String
Usage
The specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone.
Example
valueOf(fieldValue)
Signature
public static Datetime valueOf(Object fieldValue)
Parameters
- fieldValue
- Type: Object
Return Value
Type: Datetime
Usage
Use this method with the OldValue or NewValue fields of history sObjects, such as AccountHistory, when the field is a Date/Time field.
Example
valueOfGmt(dateTimeString)
Signature
public static Datetime valueOfGmt(String dateTimeString)
Parameters
- dateTimeString
- Type: String
Return Value
Type: Datetime
Usage
The specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the GMT time zone.
Example
year()
Signature
public Integer year()
Return Value
Type: Integer
Example
yearGmt()
Signature
public Integer yearGmt()
Return Value
Type: Integer