@echo off :: filename: unixtime.btm :: author: eric.pement :: date: 2014-12-06 16:10 :: requires: unixdate (date.exe from GnuWin32), sed (from GnuWin32.sf.net) :: or ssed (from sed.sf.net/grabbag/ssed), getopts :: setlocal unalias * if "%1" eq "-?" .or. "%1" eq "/?" .or. "%1" eq "--help" goto help :: GETOPTS required block starts here set F0=%@truename[%0] set chr_opts=c set str_opts=s set pass_inv=N call getopts.btm %[%@option[parameterchar]] if %? == 1 ( pause %+ goto help) for %a in ( %rev_args ) do shift /%a for %b in ( %options ) do gosub parse1 :main iff defined LC_S then :: convert epoch seconds to "YYYY-MM-SS -0600 (Central Standard Time)" unixdate -d "@%LC_S" +"%%F %%T %%z (%%Z)" elseiff "%1" ne "" then iff "%COMMA" eq "Y" then :: display specified time in epoch seconds, add commas unixdate +%%s --date="%$" | ssed -r ":a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta" else :: display specified time in epoch seconds unixdate +%%s --date="%$" endiff else iff "%COMMA" eq "Y" then :: display current time in epoch seconds unixdate +%%s | ssed -r ":a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta" else :: display current time in epoch seconds unixdate +%%s endiff endiff goto end :parse1 switch %b case c SET COMMA=Y endswitch return :help TEXT UNIXTIME - displays specified time in epoch seconds (ESEC), and also converts time from epoch seconds (since 1970-01-01 00:00:00 UTC) Usage: unixtime Show ESEC for current date/time unixtime [-c] [YYYY-MM-DD HH:MM:SS] Show ESEC for specified date/time unixtime -s ESEC Given epoch seconds, show the ISO time Options: -c Add commas (when displaying epoch seconds) -s 1234567 Convert epoch seconds to ISO time Similar commands: perl -e "print scalar time" # show current time in epoch seconds date +%s # show current time in epoch seconds echo %@eval[%@makeage[%_utcdate %_utctime] \ 10000000 - 11644473600] # TCC date -d "YYYY-MM-DD HH:MM:SS" +%s # show given date/time in epoch seconds date --date="now|1/23/2008" +FORMAT # show given date/time in another format date --date="@1234567" +"%F %T %Z" # convert epoch seconds to ISO format ENDTEXT :end unset /q chr_opts str_opts pass_inv rev_args options strings LC_S comma endlocal