Scripting Resources for DigitalMicrograph™ |
Create a Timestamp |
|
Function |
Creates a unique timestamp string. |
Version |
version: 20200129, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Converts the system time into an intuitive timestamp string. The former is in ns since 1 Jan 1970. This is convereted into a string of the form: YYYYMMDDHHMMSS, (Year, Month, Day, Hour, Minutes, Seconds). This can be useful for creating a unique label for an acquired image or data set, or adding a timestamp to the tags of data, to identify pieces of data which were acquired at the same time. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
Obviously, only specific to the nearest seconds. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Script to create a timestamp string in the format: YYYYMMDDHHMMSS // This can be used as a time-dependent label for an image or as a time // stamp for recording in a tag, when the image was recorded.
// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this address work) // version:20200129, v1.0, January 2020, www.dmscripting.com
// Source the current time. This is in nanoseconds since January 1 1970, and so is a large, and not very // intuitive, number
number year, month, day, hour, minute, second, nanosecond number time=getcurrenttime()
// Deconstruct that number into a year, month, day etc.
deconstructlocalgregoriandate(time, year, month, day, hour, minute, second, nanosecond)
// Convert the numerical dates into strings
string yearstring, monthstring, daystring, hourstring, minutestring, secondstring yearstring=""+year monthstring=""+month daystring=""+day hourstring=""+hour minutestring=""+minute secondstring=""+second
// Standardise the format of the strings, so that month, day, hour etc are always reported as two digits // ie January is reported a 01, rather than 1
if(len(monthstring)==1) monthstring="0"+monthstring if(len(daystring)==1) daystring="0"+daystring if(len(hourstring)==1) hourstring="0"+hourstring if(len(minutestring)==1) minutestring="0"+minutestring if(len(secondstring)==1) secondstring="0"+secondstring string timestring=yearstring+monthstring+daystring+hourstring+minutestring+secondstring result("\n\nCurrent Time Stamp is (YYYYMMDDHHMMSS) = "+timestring)
|