toStartOfWeek
example, the start of a week is Sunday in the United States locale, and Monday in European locales. For example:
date myDate = date.today();
date weekStart = myDate.toStartofWeek();
Returns the first of the month for the Date that called the method. For example, July 14, 1999 returns July 1, 1999.
Date toStartOfMonth
Returns the year component of a Date Integer
year
For more information on Dates, see Primitive Data Types on page 25.
Datetime Methods
The following are the system static methods for Datetime.
Apex Standard Classes and Methods
Description Return Type
Arguments Name
Constructs a DateTime and initializes it to represent the specified number of milliseconds since January 1, 1970, 00:00:00 GMT
Datetime Long l
newInstance
Constructs a Datetime from Integer representations of the year,month (1=Jan), and day at midnight in the local time zone. For example:
datetime myDate =
Constructs a Datetime from Integer representations of the year,month (1=Jan),day,hour,minute, and second in the local time zone. For example:
Datetime myDate =
Constructs a Datetime from a history tracking table field x. For more information on the anyType data type, see Datetime
anyType x newInstanceGmt
Field Types in the Force.com Web Services API Developer's Guide.
Constructs a Datetime from Integer representations of the year,month (1=Jan), and day at midnight in the
Constructs a Datetime from Integer representations of the year,month (1=Jan),day,hour,minute, and second in the GMT time zone
Datetime
Returns the current DateTime based on a GMT calendar. For example:
datetime myDateTime = datetime.now();
Datetime now
Returns a Datetime that contains the value of the specified String. The String should use the standard date Datetime
String s valueOf
format "yyyy-MM-dd HH:mm:ss" in the local time zone. For example:
Apex Standard Classes and Methods
Description Return Type
Arguments Name
string second = '20';
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
Datetime myDate =
datetime.valueOf(stringDate);
Returns a Datetime that contains the value of the specified String. The String should use the standard date Datetime
String s valueOfGmt
format "yyyy-MM-dd HH:mm:ss" in the GMT time zone
Casts x, a history tracking table field of type anyType, to a Datetime. For more information on the anyType Datetime
anyType x* valueOf
data type, see Field Types in the Force.com Web Services API Developer's Guide.
The following are the instance methods for Datetime.
Description Return Type
Arguments Name
Adds the specified number of addlDays to a Datetime.
For example:
Adds the specified number of addlHours to a Datetime Datetime
Integer addlHours addHours
Adds the specified number of addlMinutes to a Datetime
Datetime Integer
addlMinutes addMinutes
Adds the specified number of addlMonths to a Datetime
Datetime Integer addlMonths
addMonths
Adds the specified number of addlSeconds to a Datetime
Datetime Integer
addlSeconds addSeconds
Adds the specified number of addlYears to a Datetime Datetime
Integer addlYears addYears
Returns the day-of-month component of a Datetime in the local time zone of the context user. For example, February 5, 1999 08:30:12 would be day 5.
Integer day
Returns the day-of-month component of a Datetime in the GMT time zone. For example, February 5, 1999 08:30:12 would be day 5.
Integer dayGmt
Apex Standard Classes and Methods
Description Return Type
Arguments Name
Returns the day-of-year component of a Datetime in the local time zone of the context user. For example, February 5, 2008 08:30:12 would be day 36.
Datetime myDate =
Returns the day-of-year component of a Datetime in the GMT time zone. For example, February 5, 1999 08:30:12 would be day 36.
Integer dayOfYearGmt
Returns a Datetime as a string using the local time zone of the current user. If the time zone cannot be
determined, GMT is used.
String format
Returns a Datetime as a string using the supplied Java simple date format and the local time zone of the current String
String dateFormat format
user. If the time zone cannot be determined, GMT is used. For example:
datetime myDT = Datetime.now();
String myDate = myDT.format('h:mm a');
For more information on the Java simple date format, see
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html. Returns a Datetime as a string using the supplied Java simple date format and time zone. If the supplied time zone is not in the correct format, GMT is used.
For more information on the Java simple date format, see
Returns a Datetime as a string using the supplied Java simple date format and the GMT time zone.
For more information on the Java simple date format, see
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html. String
StringdateFormat formatGmt
Returns a Datetime using the local time zone of the current user, including seconds and time zone String
formatLong
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object
Long getTime
Returns the hour component of a Datetime in the local time zone of the context user
Integer hour
Returns the hour component of a Datetime in the GMT time zone
Integer hourGmt
Apex Standard Classes and Methods
Description Return Type
Arguments Name
Returns true if the Datetime that called the method is the same as the compDt in the local time zone of the
Return the millisecond component of a Datetime in the local time zone of the context user.
Integer millisecond
Returns the minute component of a Datetime in the local time zone of the context user
Integer minute
Returns the minute component of a Datetime in the GMT time zone
Integer minuteGmt
Returns the month component of a Datetime in the local time zone of the context user (1=Jan)
Integer month
Returns the month component of a Datetime in the GMT time zone (1=Jan)
Integer monthGmt
Returns the second component of a Datetime in the local time zone of the context user
Integer second
Returns the second component of a Datetime in the GMT time zone
Integer secondGmt
Returns the year component of a Datetime in the local time zone of the context user
Integer year
Returns the year component of a Datetime in the GMT time zone
Integer yearGmt
For more information about the Datetime, see Primitive Data Types on page 25.