Search code examples
stringdatetimedm-script

Getting datestamp in known format


As far as I can tell the following functions are what is available and they all depend on the date/time settings of the system:

GetTime()
GetDate()
DateStamp()
GetCurrentTime().FormatTimeString()

This makes for pretty timestamps in the result window but is really problematic for putting timestamps into filenames. Is there a command that will get me the date and time in a system-independent format, or do I need to write some crazy function to do it myself?


Solution

  • Have you checked out the commands availble from the help documentation, section "Utility Functions" ? In particular the parameters for

    String FormatTimeString( Number time, Number format )

    enter image description here

    Or if you want to construct something "crazy" this might be helpful:

    void DeconstructLocalGregorianDate( Number time, NumberVariable year, NumberVariable month, NumberVariable day, NumberVariable hour, NumberVariable minute, NumberVariable second, NumberVariable nanosecond )

    You can use it like in the following example:

    enter image description here

    Number year, month, day 
    Number hour, minute, second, nanosecond 
    GetCurrentTime().DeconstructLocalGregorianDate( year, month, day, hour, minute, second, nanosecond )
    string myFormat = year+"_"+month+"_"+day+"--"+hour+"-"+minute+"-"+second
    OKDialog( myFormat )