Skip to main content
1-Visitor
December 9, 2015
Solved

Current time in a service

  • December 9, 2015
  • 3 replies
  • 8468 views

Hello all,

I have what seems like it should be a simple question, but I cant seem to find the answer to it.  I have an event that triggers a subscription.  I have with it the start time of a cycle of a machine, and I would like to get the cycle duration.  I am not being sent up the cycle stop time, so I am going to have to use the current time-cycle start.  How can I get the current time in my service?  I have tried

var currentdate = new Date();

var result=currentdate.getDate()

and it gives me a time in 1969 haha.  Is there an easy way to get the current time stamp?  It should be easy because anytime a property is logged it is used, but I am stumped!

Thank you!

Best answer by byutz

Just found the answer!

var currentdate = Date.now();

var result=currentdate

3 replies

byutz1-VisitorAuthorAnswer
1-Visitor
December 9, 2015

Just found the answer!

var currentdate = Date.now();

var result=currentdate

5-Regular Member
December 11, 2015

Just doing this also works:

var now= new Date();

result=now;

1-Visitor
December 14, 2015

Thingworx 5.0+ get current date and time using Javascript source code

https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS218294