-1

Can anyone let me know how to convert a string to a date Object with UTC time zone in ExtJs?

String is "2015-10-07T23:59:00". I would like to get the same in Date Object without changing the timezone.

Tarabass
  • 3,132
  • 2
  • 17
  • 35
Kumar
  • 183
  • 1
  • 12
  • Append the `Z` timezone stamp on the end and the parser will know the zone `"2015-10-07T23:59:00Z"`. If you're working with the native _Date_ make sure you use the _UTC methods_ thereafter too – Paul S. Oct 07 '15 at 14:02

3 Answers3

1

First of all, your date string does not have a timezone.

When you make a JavaScript date object from a string, there are two possible outcomes you could expect:

  • You may want the date to be 23:59 Local (23:59 CEST in my case).
    In this case, you want to use new Date("2015-10-07 23:59:00") with plain javascript (note the missing T), or Ext.Date.parse("2015-10-07T23:59:00","c");.
  • You may want the date to be 23:59 UTC (e.g. 01:59 CEST).
    In this case, you want to use new Date("2015-10-07T23:59:00").

Of course, whenever you output the date, you have to get the date in the correct time zone as well. The console/toString will usually show it in local time. JavaScript does provide getUTC... methods if you require other time zones.

You see, using Time Zones with JavaScript is a painful experience. I would recommend to try moment.js if you need full time zone support.

Alexander
  • 19,906
  • 19
  • 75
  • 162
0

You can use Ext.Date.parse.It gives Date Object as output.It syntax is:

Ext.Date.parse( String input, String format, [Boolean strict] )

For Example:

Ext.Date.parse("2015-10-07T23:59:00", "Y-m-dTH:i:s");
Ankit Chaudhary
  • 4,059
  • 1
  • 11
  • 23
0

try

var millisFromEpoch = Date.parse('2015-10-07T23:59:00');

it will parse date in GMT timezone, Ext.date.parse use the current timezone instead

Mattex83
  • 86
  • 1
  • 2
  • Yeah I tried..but changing the above time to gmt gives "2015-10-08 00:00:00"...I want it to be in same timezone.. – Kumar Oct 07 '15 at 15:43