0

I have an ASP.NET Web API endpoint where I can POST some data.

Let's say I will post the following:

var myObject = {
name: "Jhon Smith",
age: "34",
accountCreated: "CURRENT DATE TIME"
};

what is the equivalent of DateTime.Now in JavaScript so I can assign the current date and time to accountCreated?

How can I parse this date (javascript current date time) into a C# DateTime object (in ASP.NET)?

3 Answers 3

1

You can use new Date() is the equivalent of DateTime.Now

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

Comments

1

Just :

new Date().getTime();

1 Comment

I did use it and the result parsed in ASP.NET is {1/1/0001 12:00:00 AM}
0

The equivalent to DateTime.Now in JS would be new Date(). I wouldn't be relying on that sort of information from the client anyway as that isn't really the created date.

To ensure consistency with your dates it's best to leave that sort of stuff to the server where you can be sure that the DateTime used is in fact the true DateTime of when the record was created.

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.