0

I have a c# DateTime passed to the client as: 1980-01-20T00:00:00

How do i convert it to javascript DateTime? I tried doing

var date = new Date(1980-01-20T00:00:00) but this gives me an error
0

2 Answers 2

3

Put it in quotes:

var date = new Date("1980-01-20T00:00:00")

var date = new Date("1980-01-20T00:00:00")
alert(date)

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

3 Comments

Only problem with this is:This will only work if you know the date format is right.. This works as long as you make sure thats the case.
@MarkSmit it will be the correct format, always, cause it is the default C# DateTime format, which cannot change.
It actually does change if you avoid your application to use the invariant culture.
1

What you need is the amount of miliseconds from 1970:

long epochTicks = new DateTime(1970, 1, 1).Ticks
long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
long javascriptTyme=unixTime*1000;

Thats the value you want to send to javascript

Comments

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.