1 Reply Latest reply on Aug 24, 2009 5:16 AM by Chunick

    Xtra or Function to create parse POSIX (Unix) Time

    TJW-dev

      Hi,

       

      does anyone know of an xtra, or can point me to an example function for encoding and decoding a date \ time stamp into POSIX (UNIX time) ?

      Ideally to do time based calculations on it as well, such as time difference etc.

       

      Thanks

       

      Tim

        • 1. Re: Xtra or Function to create parse POSIX (Unix) Time
          Chunick Level 3

          If you are using DMX2004 or above then you can use the Javascript Date Object. Here's a nice list I've compiled, but it was for some web work, so ultimately you will have to test if all the functions work in Director's version of Javascript (ECMAScript):

           

          Date Object Properties
          constructor        // Returns a reference to the Date function that  created the object
          prototype        // Allows you to add properties and methods to the object

          Date Object Methods
          Date()            // Returns today's date and time

          getTime()        // returns the number of milliseconds since midnight of  January 1, 1970.

          getFullYear()        // year as 4-digit
          getYear()        // *Depricated. year as 2-digit or 3- or 4-digit
          getMonth()        // month (0-11)
          getDate()         // day of month (1-31)
          getDay()         // day of week    (0-6)
          getHours()        // hours (0-23)
          getMinutes()        // minutes (0-59)
          getSeconds()        // seconds (0-59)
          getMilliseconds()    // milliseconds (0-999)

          getTimezoneOffset()    // in minutes, eg. 240 = 240 minutes = 4 hours =  GMT-0400 (Eastern Daylight Time)

          getUTCFullYear()    //
          getUTCMonth()        //
          getUTCDate()        //
          getUTCDay()        //
          getUTCHours()        //
          getUTCMinutes()        //
          getUTCSeconds()        //
          getUTCMilliseconds()    //

          parse()            // takes a date string and returns the number of  milliseconds since January 1, 1970

          setDate(day)        // set day of month
          setTime(millisec)    // calculate a date and time by adding or  subtracting a specified number of milliseconds to/from midnight January  1, 1970.

          setFullYear(year,month,day) // year = required, month, day (of month) =  optional
          setMonth(month,day)       // month = required, day (of month) = optional
          setHours(hour,min,sec,millisec)        //hour = required,  min,sec,millisec = optional
          setMinutes(min,sec,millisec)        //min = required, sec,millisec =  optional
          setSeconds(sec,millisec)        //sec = required, millisec = optional
          setMilliseconds(millisec)        //millisec = required

          setUTCDate()

          setUTCFullYear()
          setUTCMonth()
          setUTCHours()
          setUTCMinutes()
          setUTCSeconds()
          setUTCMilliseconds()

          toDateString()        // returns the date portion of a Date object in  readable form
          toGMTString()        // converts a Date object, according to Greenwich  time, to a string
          toUTCString()        // converts a Date object, according to universal  time, to a string
          toLocaleDateString()    // converts a Date object, according to local  time, to a string and returns the date portion.
          toLocaleTimeString()    // converts a Date object, according to local  time, to a string and returns the time portion
          toLocaleString()    // converts a Date object, according to local time,  to a string
          toSource()        // represents the source code of an object // not  specifically for Date object
          toString()        // converts a Date object to a string
          toTimeString()        // returns the time portion of a Date object in  readable form
          UTC()            // takes a date and returns the number of milliseconds  since midnight of January 1, 1970 according to universal time
          valueOf()        // returns the primitive value of a Date object



          // set Date object to a specific date (14th January 2010)
          // Note: 0=January, 11=December, it's base-0
          var myDate = new Date();
          myDate.setFullYear(2010,0,14);

          // adds 5 days to the current date
          var myDate=new Date();
          myDate.setDate(myDate.getDate()+5);


          // Compare Two Dates
          var myDate=new Date();
          myDate.setFullYear(2010,0,14);
          var today=new Date();
          trace(myDate>today);
          //true