Skip to content

Instantly share code, notes, and snippets.

@sunitJindal
Last active January 20, 2016 09:47
Show Gist options
  • Select an option

  • Save sunitJindal/a4bb2b6a31869a7eec02 to your computer and use it in GitHub Desktop.

Select an option

Save sunitJindal/a4bb2b6a31869a7eec02 to your computer and use it in GitHub Desktop.

Revisions

  1. sunitJindal revised this gist Jan 20, 2016. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions date-timezone.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // Local time zone is Asia/Kolkata with offset GMT +0530

    var dt = "14/02/2016";
    var dt = "14/03/2016";
    var dtz = "14/03/2016 +0130";
    var tz = "+0130";
    var df = "DD/MM/YYYY";
    @@ -15,22 +15,22 @@ d1.format()
    // "2016-03-14T04:00:00+05:30"

    d2.format()
    // "2016-02-14T00:00:00+05:30"
    // "2016-03-14T00:00:00+05:30"

    d3.format()
    // "2016-03-14T00:00:00+01:30"

    d4.format()
    // "2016-02-13T20:00:00+01:30"
    // "2016-03-13T20:00:00+01:30"

    d1.toDate()
    // Mon Mar 14 2016 04:00:00 GMT+0530 (IST)

    d2.toDate()
    // Sun Feb 14 2016 00:00:00 GMT+0530 (IST)
    // Mon Mar 14 2016 00:00:00 GMT+0530 (IST)

    d3.toDate()
    // Mon Mar 14 2016 04:00:00 GMT+0530 (IST)

    d4.toDate()
    // Sun Feb 14 2016 00:00:00 GMT+0530 (IST)
    // Mon Mar 14 2016 00:00:00 GMT+0530 (IST)
  2. sunitJindal revised this gist Jan 20, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions date-timezone.js
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,10 @@ var tz = "+0130";
    var df = "DD/MM/YYYY";
    var dfz = "DD/MM/YYYY Z";

    var d1 = moment(dtz,dfz);
    var d2 = moment(dt,df);
    var d3 = moment(dtz,dfz).utcOffset(tz);
    var d4 = moment(dt,df).utcOffset(tz);
    var d1 = moment(dtz,dfz); // date string with time zone
    var d2 = moment(dt,df); // date string without timezone
    var d3 = moment(dtz,dfz).utcOffset(tz); // date string with time zone. Apply UTC offset after moment is created
    var d4 = moment(dt,df).utcOffset(tz); // date string without time zone. Apply UTC offset after moment is created

    d1.format()
    // "2016-03-14T04:00:00+05:30"
  3. sunitJindal created this gist Jan 20, 2016.
    36 changes: 36 additions & 0 deletions date-timezone.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    // Local time zone is Asia/Kolkata with offset GMT +0530

    var dt = "14/02/2016";
    var dtz = "14/03/2016 +0130";
    var tz = "+0130";
    var df = "DD/MM/YYYY";
    var dfz = "DD/MM/YYYY Z";

    var d1 = moment(dtz,dfz);
    var d2 = moment(dt,df);
    var d3 = moment(dtz,dfz).utcOffset(tz);
    var d4 = moment(dt,df).utcOffset(tz);

    d1.format()
    // "2016-03-14T04:00:00+05:30"

    d2.format()
    // "2016-02-14T00:00:00+05:30"

    d3.format()
    // "2016-03-14T00:00:00+01:30"

    d4.format()
    // "2016-02-13T20:00:00+01:30"

    d1.toDate()
    // Mon Mar 14 2016 04:00:00 GMT+0530 (IST)

    d2.toDate()
    // Sun Feb 14 2016 00:00:00 GMT+0530 (IST)

    d3.toDate()
    // Mon Mar 14 2016 04:00:00 GMT+0530 (IST)

    d4.toDate()
    // Sun Feb 14 2016 00:00:00 GMT+0530 (IST)