Convert DateTime to Ticks Javascript or Jquery

Abhilash Nagar
Abhilash Nagar used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It should be sum of ticks since the epoch and ticks between 1st Jan 0001 and 1st Jan 1970.

var ticks = ((yourDateObject.getTime() * 10000) + 621355968000000000);
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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

Abhilash Nagar.NET Developer

Author

Commented:
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
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Great - suggestion - next time mention you need a TimeZone offset and we will include it in the solution - but glad you are working.
Abhilash Nagar.NET Developer

Author

Commented:
Thanks for all responses, great help!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial