Docs > API > Date
PostCMS Date objects are very similar to Date objects in normal JavaScript. For example:
out.write(new Date().getTime());However, the PostCMS API provides some additional methods that are not part of the standard JavaScript Date library, e.g.
// => 1223657278130
out.write(new Date().format('yyyy-MM-dd'));
// => 2008-10-10| Methods | |
|---|---|
| Date.difference(date1, date2) | A string representation of the difference between two date objects. |
| Date.format( dateString, formatString) | Format a date string using the format string. The return value is a string, NOT a Date object, e.g.Date.format("20080808", "yyyy");The date string should be in the format "yyyyMMdd" or "yyyyMMddHHmm". |
| Date.friendlyFormat( dateString) | A string representaton of the given date-string in an easily-readable format.Date.friendlyFormat("200810101300"); |
| Date.make(dateString [, formatString]) | Create a JavaScript Date object from a date string and (optionally) a format string specifying the date string's format. If the format string is not specified, the date string is assumed to be in the format "yyyyMMddHHmm", e.g.d1 = Date.make('200808081300'); |
| add(amount, unit) | Add the specified number of units to this date object. The valid units are "year", "month", "week", "day"/"date", "hour", and "minute", and the amount may be negative.d1 = new Date(); |
| difference(otherDate) | A string representation of the difference between this date object and another date object. |
| format(formatString) | A string representation of this date object in the given format. |
| friendlyFormat() | A string representation of this date in an easily-readable format. |



