astralmaster
astralmaster

Reputation: 2465

Determine DateTime format for API C#

I am reading an API documentation that says I have to pass current time to it in following format:

{
   "date": "\/Date(1508262132936)\/"
}

And the one-line explanation of this format says: "Date in UTC format". I tried passing DateTime.Now; DateTime.Now.UtcNow; DateTime.Now.ToUniversalTime(); but all of those output BadRequest reply. What is the correct format here?

Upvotes: 0

Views: 457

Answers (1)

Kevin Smith
Kevin Smith

Reputation: 14456

Looks like a Unix epoch time, use the ToUnixTimeSeconds method on DateTimeOffset:

var date = DateTime.UtcNow;
new DateTimeOffset(date).ToUnixTimeSeconds()

Upvotes: 2

Related Questions