Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get epoch time using a Windows command?

Is there a way to get time using a Windows command? If not, can the date and time commands output be modified?

For example date in Windows gives the date with / etc. I would like to get an output that has no special characters such as / :

like image 959
moorecats Avatar asked Aug 10 '10 22:08

moorecats


2 Answers

Use this command to show numbers of seconds after epoch.

(Cmd command)

powershell -command "(New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date)).TotalSeconds"

like image 116
Benjamin2002 Avatar answered Oct 06 '22 03:10

Benjamin2002


The CoreUtils for Windows project, http://gnuwin32.sourceforge.net/packages/coreutils.htm has a date command, which give you the same options as under Linux.

Download the software, and rename date.exe to gnudate.exe, to avoid a conflict with the Dos date command. You need the files libintl-2.dll and libiconv-2.dll to run the command.

For all available options type:

gnudate --help 

For example gnudate "+%a %e %b %Y %H:%M:%S" will give:

Sun 10 apr 2016 21:52:35

The command gnudate +%s will give the seconds since Epoch:

1460325461

The next Dos batch file shows the usage of gnudate. You will need to double the % in the gnudate +%s parameter.

rem set the variable s to the epoch seconds.
for /f "tokens=1 delims=" %%A in ('gnudate +%%s') do set s=%%A
rem use `%s%` for the time offset parameter of the ffmpeg drawtext filter.
ffmpeg -y -f lavfi -i testsrc=duration=15.3:size=cif:r=10 -vf "drawtext=fontfile=arial.ttf:text=%%{pts\\\:localtime\\\:%s%\\\:%%a %%d %%b %%Y %%H\\\\\\:%%M\\\\\\:%%S}:fontsize=10:x=w-text_w:y=h-lh:box=1" a.mp4

ffplay a.mp4

This batch file was tested with Windows 8 in a virtual machine under Linux.

To run it, you'll need to install ffmpeg.
You can download the Static build from https://ffmpeg.zeranoe.com/builds/.

like image 38
Arjen Rodenhuis Avatar answered Oct 06 '22 04:10

Arjen Rodenhuis