The lastest version of this document is available on Github > datetime-object

Converters Section

fromDate

var date=new Date(); var dt=DateTime.fromDate(date);

fromMoment

Create a DateTime from a moment object var mmt=moment(); var dt=DateTime.fromMoment(mmt);

fromObject

DateTime.fromObject{unit: value, ...}); DateTime.fromObject({ hour:15, minute:10 }); DateTime.fromObject({ y :2010, M :3, d :5, h :15, m :10, s :3, ms :123}); DateTime.fromObject({ year :2010, month :3, day :5, hour :15, minute :10, second :3, millisecond :123}); You can create a DateTime by specifying some of the units in an object. Omitted units default to 0 or the current date, month, and year. `day` and `date` key both mean day-of-the-month. Note that `new Date(year, month, date)`, months are 0 indexed.

fromUnixEpoch

var timestamp=DateTime.fromUnixEpoch();

toUnixEpoch

var timestamp=DateTime.now().toUnixEpoch();

toDate

This will return a copy of the `Date` that the DateTime uses, so any changes to that `Date` will not cause DateTime to change. If you want to change the DateTime `Date`, see `DateTime#manipulate` or `DateTime#set`.

toJSON

When serializing an object to JSON, if there is a `DateTime` object, it will be represented as an ISO8601 string, adjusted to UTC. JSON.stringify({ postDate : new DateTime() }); If instead you would like an ISO8601 string that reflects the DateTime's `utcOffset()`, then you can modify the `toJSON` function like this: DateTime.fn.toJSON = function() { return this.toString(); } This changes the behavior as follows: JSON.stringify({ postDate : new DateTime() });

toISOString

new DateTime().toISOString(); new DateTime().toISOString(keepOffset); Formats a string to the ISO8601 standard. new DateTime().toISOString() Note that `.toISOString()` returns a timestamp in UTC, even if the DateTime in question is in local mode. This is done to provide consistency with the specification for native JavaScript Date `.toISOString()`, as outlined in the ES2015 specification .

toObject

returns an object containing year, month, day-of-month, hour, minute, seconds, milliseconds attributes. new DateTime().toObject()

toMoment

Create a Moment from a DateTime instance var dt=new DateTime().toMoment(); returns an moment.