cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Current time in a service

byutz
1-Newbie

Current time in a service

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!

1 ACCEPTED SOLUTION

Accepted Solutions
byutz
1-Newbie
(To:byutz)

Just found the answer!

var currentdate = Date.now();

var result=currentdate

View solution in original post

3 REPLIES 3
byutz
1-Newbie
(To:byutz)

Just found the answer!

var currentdate = Date.now();

var result=currentdate

pschmaltz
10-Marble
(To:byutz)

Just doing this also works:

var now= new Date();

result=now;

qn
1-Newbie
1-Newbie
(To:byutz)

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

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

Top Tags