1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unix time conversion

Discussion in 'Support' started by Eric Pement, Nov 18, 2008.

  1. Eric Pement

    Joined:
    Jun 28, 2008
    Messages:
    12
    Likes Received:
    0
    Are there any functions or scripts to convert the current date/time or a user-specified date/time to UNIX epoch seconds (seconds since 1970-01-01 00:00:00 UTC) ?

    I see that %@makeage[] and %@agedate[] are good contenders, but I want the UNIX time stamp system, not the NTFS time stamp system. TIA for any help.

    This is not urgent. In the interim, I have written a batch file that uses date.exe from the core-utils package at GnuWin32.sourceforge.net. I just wanted to know if I could have done the same thing with TCC functions.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    On Tue, 18 Nov 2008 20:48:18 -0600, Eric Pement <> wrote:


    You could easily build your own.

    function utime `%@eval[%@makeage[%_date %_time] \ 10000000 - 11644473600]`

    echo %@utime[]
    1227048797

    I could put a _UTIME variable in my 4UTILS plugin.
     
  3. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    605
    Likes Received:
    0
    You could wrap your own function to use the age functions and subtract and
    divide. I don't have handy TCC references with me just now, but look up the
    user functions.

    On Tue, Nov 18, 2008 at 6:48 PM, JP Software Forums <neil@jpsoft.com> wrote:




    --
    Jim Cook
    2008 Fridays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
    Next year they're Saturday.
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    Better change that to:

    function utime `%@eval[%@makeage[%_utc] \ 10000000 - 11644473600]`
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    Oops! I should have said:

    function utime `%@eval[%@makeage[%_utcdate %_utctime] \ 10000000 - 11644473600]`

    (%_uct works but is from the 4UTILS plugin.)
     
  6. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    I use these functions, but they're not adjusted for UTC:


    function unixtodate=`%@agedate[%@eval[%@if[%@eval[%1 - 0x80000000] lt 0,%1,(%1 - 0x100000000)]*10000000 + %@makeage[1970-1-1]]]`

    function datetounix=`%@eval[(86400 * (3652 + %@date[0%1])) + %@time[0%2]]`


    You can adjust for your offset from UTC by adding (%_tzo * 60) to the local time in the datetounix function.
     
  7. Eric Pement

    Joined:
    Jun 28, 2008
    Messages:
    12
    Likes Received:
    0
    Just want to say thanks to you and the others who provided such a speedy reply. I appreciate it!
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    On Thu, 20 Nov 2008 13:39:10 -0600, Eric Pement <> wrote:


    It can be made into a variable as well (instead of a variable function).

    set _UTIME=`%@eval[%@makeage[%_utcdate %_utctime] \ 10000000 - 11644473600]`

    echo %_utime
    1227210439
     

Share This Page