0

I have a string 2016-01-04T15:30:00 coming from c# DateTime. When I convert it to a javascript Date object var jDate = new Date(2016-01-04T15:30:00); the time is getting changed based on the local time zone
Console Output: Mon Jan 04 2016 10:30:00 GMT-0500 (Eastern Standard Time)
How can I get the date to have the time 15:30 and not 10:30?

The answer should return a Date object so I can do date.getHours()

4
  • Try this. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Jan 5, 2016 at 17:03
  • I need a Date object because I use it to get the hours,min... I'm just not getting the correct time Commented Jan 5, 2016 at 17:08
  • jDate.getUTCHours() will give you 15. Commented Jan 5, 2016 at 17:52
  • Thanks, this is all I needed for my code to work because I don't care what the time is on the date itself Commented Jan 5, 2016 at 19:00

1 Answer 1

1

You need to cahnge the DateTime Kind to Unspecified,

DateTime.SpecifyKind(saveNow, DateTimeKind.Unspecified);

Read more here :

https://msdn.microsoft.com/en-us/library/system.datetime.specifykind(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Just a tip: indent code by four spaces to make a code sample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.