0

All:

Thanks for help. I wonder how can I build a Date object using local time string, for example:

If I use new Date("2016-07-01"), what I want to build is

2016-07-01 00:00:00 GMT-0800 (Pacific Standard Time) (say I am in San Francisco),

but right now, it gives me something like

Thu Jun 30 2016 16:00:00 GMT-0800 (Pacific Standard Time)

Any idea?

Kuan
  • 11,149
  • 23
  • 93
  • 201
  • http://stackoverflow.com/questions/4744299/how-to-get-datetime-in-javascript – amflare Jul 01 '16 at 22:43
  • @amflare Thanks, but sorry I guess I did not quite catch ur point, the problem I try to describe is when I use a Date/time string, the new Date() always treat it as from UTC time zone, I try to make that time as indicating my local time. – Kuan Jul 01 '16 at 22:48
  • http://stackoverflow.com/a/20834878/5937428 – amflare Jul 01 '16 at 22:49
  • https://stackoverflow.com/questions/22184747/parse-string-to-date-with-moment-js – Anthony Astige Jul 01 '16 at 22:58
  • @AnthonyAstige Thanks, could you give one example how can I build a time object which indicate 2016-01-01 00:00:00 in San Francisco local. with "2016-01-01" only? – Kuan Jul 01 '16 at 23:03
  • https://github.com/rhroyston/clock-js – Ronnie Royston Jul 02 '16 at 05:01

1 Answers1

0

To convert the default UTC time created from running new Date(dateString):

const MILLISECONDS_PER_MINUTE = 60000;
const utcDate = new Date('2015-01-01');
console.log(new Date(utcDate.getTime() + (utcDate.getTimezoneOffset() * MILLISECONDS_PER_MINUTE))); // Wed Jan 01 2014 00:00:00 GMT-0700 (MST)
jpumford
  • 573
  • 2
  • 9
  • Thanks, but sorry I guess I did not quite catch ur point, the problem I try to describe is when I use a Date/time string, the new Date() always treat it as from UTC time zone, I try to make that time as indicating my local time. – Kuan Jul 01 '16 at 22:48