Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WAT JavaScript Date

othree
August 10, 2017

WAT JavaScript Date

othree

August 10, 2017
Tweet

More Decks by othree

Other Decks in Programming

Transcript

  1. “Wat” is a variant of the English word “what” that

    is often used to express confusion or disgust, much like its better known acronym “WTF,” short for “what the fuck.” http://knowyourmeme.com/memes/wat
  2. // Firefox latest new Date("2005-07-08"); // Date 2005-07-08T00:00:00.000Z // July

    8th 00:00 UTC new Date("2005/07/08"); // Date 2005-07-07T16:00:00.000Z // July 8th 00:00 local time
  3. // Firefox latest new Date("2005-07-08"); // Date 2005-07-08T00:00:00.000Z // July

    8th 00:00 UTC new Date("2005/07/08"); // Date 2005-07-07T16:00:00.000Z // July 8th 00:00 local time (Date.parse("2005-07-08") - Date.parse("2005/07/08")) / 36e5 // 8 hours
  4. // Firefox latest new Date("2005-07-08"); // Date 2005-07-08T00:00:00.000Z // July

    8th 00:00 UTC new Date("2005/07/08"); // Date 2005-07-07T16:00:00.000Z // July 8th 00:00 local time (Date.parse("2005-07-08") - Date.parse("2005/07/08")) / 36e5 // 8 hours // Chrome latest new Date("2005-07-08");
  5. // Firefox latest new Date("2005-07-08"); // Date 2005-07-08T00:00:00.000Z // July

    8th 00:00 UTC new Date("2005/07/08"); // Date 2005-07-07T16:00:00.000Z // July 8th 00:00 local time (Date.parse("2005-07-08") - Date.parse("2005/07/08")) / 36e5 // 8 hours // Chrome latest new Date("2005-07-08"); // Fri Jul 08 2005 08:00:00 GMT+0800 (CST) // July 8th 00:00 local time
  6. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z
  7. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z // 2 -> March, 0 based
  8. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z // 2 -> March, 0 based // UTC Time: 03/02 16:00 // UTC+8 Time: 03/03 00:00
  9. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z // 2 -> March, 0 based // UTC Time: 03/02 16:00 // UTC+8 Time: 03/03 00:00 theday.getDate() // 3 theday.getUTCDate() // 2
  10. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z // 2 -> March, 0 based // UTC Time: 03/02 16:00 // UTC+8 Time: 03/03 00:00 theday.getDate() // 3 theday.getUTCDate() // 2 new Date(2017, 2, 3, 8, 0, 0, 0); // Date 2017-03-03T00:00:00.000Z
  11. // Firefox var theday = new Date(2017, 2, 3, 0,

    0, 0, 0); // Date 2017-03-02T16:00:00.000Z // 2 -> March, 0 based // UTC Time: 03/02 16:00 // UTC+8 Time: 03/03 00:00 theday.getDate() // 3 theday.getUTCDate() // 2 new Date(2017, 2, 3, 8, 0, 0, 0); // Date 2017-03-03T00:00:00.000Z new Date(Date.UTC(2017, 2, 3, 8, 0, 0, 0)); // Date 2017-03-03T08:00:00.000Z
  12. [[_?[ 㗢 Y?CSYG6Q;6M?Q=6YSQMh 㗢 _]69M?㗦 SSY =?[GCQ 㗢 㖍96[?=OSQ]E 㗢

    *Q?fU?;]?=U6Y[?Y9?E6aGSY 㗢 S(GO?4SQ?6Q=&([_UUSY] 㗢 S=_Y6]GSQ㗦U?YGS=
  13. // momentjs var thedate = moment("20170131", "YYYYMMDD"); thedate.add(2, 'months').format(); //

    "2017-03-31T00:00:00+08:00" thedate.add(1, 'months').add(1, 'months').format();
  14. // momentjs var thedate = moment("20170131", "YYYYMMDD"); thedate.add(2, 'months').format(); //

    "2017-03-31T00:00:00+08:00" thedate.add(1, 'months').add(1, 'months').format(); // "2017-03-28T00:00:00+08:00"
  15. // momentjs var thedate = moment("20170131", "YYYYMMDD"); thedate.add(2, 'months').format(); //

    "2017-03-31T00:00:00+08:00" thedate.add(1, 'months').add(1, 'months').format(); // "2017-03-28T00:00:00+08:00" thedate.add(1, 'months').format(); // "2017-02-28T00:00:00+08:00"
  16. var thedate = LocalDate.parse('2017-01-31').atStartOfDay(); var after2m = thedate.plusMonths(2); after2m.toString(); //

    "2017-03-31T00:00" var sixtydays = Duration.ofDays(60); thedate.plus(sixtydays).toString(); // "2017-04-01T00:00" ZonedDateTime.now(ZoneId.of('Europe/Paris')).toString(); // "2017-02-04T17:01:15.846+01:00[Europe/Paris]"
  17. ]?OUSY6M 㗢 ?dUYSUS[6M 㗢 S=6MGK? =?[GCQ 㗢 6CCG? GQ]㘵G;YS[SA]㘸 㗢

    6]]SEQ[SQ㘵G;YS[SA]㗦6_]ESYSASO?Q]㗿I[㘸 㗢 YG6Q(?YM[SQ㘵G;YS[SA]㘸
  18. var ldt = new temporal.LocalDateTime(2017, 12, 31, 23, 59); var

    addHours = new temporal.LocalDateTime( 2017, 12, 31, 23, 00).add(2, 'hours'); var zdt = new temporal.ZonedDateTime('America/New_York', 2017, 12, 31, 23, 59);
  19. var ldt = new CivilDateTime(2017, 12, 31, 23, 59); var

    addHours = new CivilDateTime(2017, 12, 31, 23, 00) .add(2, 'hours'); var zdt = ldt.withZone(‘America/New_York');