How to store time

Tags: 

Here is an example of how to store the Unix Epoch time for any number of reasons:

storeEval | new Date().getTime(); | currentTime

You can you this to:

  • Time page loads
  • Get a unique non-repeatable number (unique ID)
  • Get the current time

Another example for use with a formatted date:

storeEval | var d=new Date(); ((d.getMonth()+1))+'-'+d.getDate()+'-'+d.getFullYear(); | formattedDate

Will return: MM-DD-YYYY

Another example showing date and time:

storeEval | var d=new Date(); ((d.getMonth()+1))+'/'+d.getDate()+'/'+d.getFullYear()+' - '+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds() | fullyFormattedDate

Will return: MM/DD/YYYY - HH:M:SS

Yet another example that will display: 12/3/2013 2:16:04 PM (notice that there are leading zeros (padded) for the seconds. Padding will also happen for the Minutes value. Helpful if you are going to export to Excel and attempt to sort the values.

storeEval | var d=new Date(); ((d.getMonth()+1))+'/'+d.getDate()+'/'+d.getFullYear() | date

storeEval | var Today = new Date(); Today.toLocaleTimeString(); | time

store | ${date} ${time} | runDate

echo | ${runDate}