Link to home
Start Free TrialLog in
Avatar of Abhilash Nagar
Abhilash Nagar

asked on

Convert DateTime to Ticks Javascript or Jquery

Hello,
Can someone please suggest how to convert date like below to ticks
May 09 2019 23:59:59 to ticks in jquery or javascript?

Correct ticks conversion value should be :

636930431999990000

As per this link:
https://tickstodatetime.azurewebsites.net/

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
var TICK_CONSTANT = 621355968000000000;
var dateStr = 'May 09 2019 23:59:59';
var date = new Date(dateStr);
var ticks = ((date.getTime() * 10000) + TICK_CONSTANT);
console.log(ticks)

Open in new window

Avatar of Abhilash Nagar
Abhilash Nagar

ASKER

Thanks for the response. Yes your solution is correct but to match it exactly to .NET  i did this :

((yourDateObject.getTime() * 10000) + 621355968000000000)-(yourDateObject.getTimezoneOffset() * 600000000);

Below link :
https://stackoverflow.com/questions/7966559/how-to-convert-javascript-date-object-to-ticks
Great - suggestion - next time mention you need a TimeZone offset and we will include it in the solution - but glad you are working.
Thanks for all responses, great help!!