Is there any way to get an era using the windows command?

Is there any way to get an era using the windows command? If not, can the date and time commands be changed?

For example, date on Windows gives a date with / etc. I would like to get output that has no special characters like /:

+7
windows cmd batch-file
source share
5 answers

To get the time in yyyymmdd format, try the following:

 for /F "tokens=2-4 delims=/ " %i in ('date /t') do echo %k%i%j 

More details:

http://www.sprint.net.au/~terbut/usefulbox/msdoscmds.htm

0
source share

from the command line try this

 for /f "tokens=2,3,4 delims=/ " %f in ('date /t') do @echo %h%g%f 

remember to double% chars if in a batch file

 @echo off setlocal for /f "tokens=2,3,4 delims=/ " %%f in ('date /t') do set d=%%h%%g%%f for /f "tokens=1,2 delims=: " %%f in ('time /t') do set t=%%f%%g echo datetime is : %d%%t% endlocal 

I got this conclusion:

 c:\development>xx.bat datetime is : 201008111108 
+2
source share

Through my own online research, I could not find a way to do this directly through a batch file. However, I was able to find this solution that worked for me:

In toEpoch.vbs:

 WScript.Echo DateDiff("s", "01/01/1970 00:00:00", Now()) 

It is then called from my batch script as follows:

 for /f "delims=" %%x in ('cscript /nologo toEpoch.vbs') do set epoch=%%x 

Set the% epoch% to the current unix timestamp, and I was able to use it the way I needed.

Hope this helps.

+2
source share

There is no reliable way to get the date in batch files without resorting to external tools or other languages ​​such as VBScript.

In VBScript, you can access the current date and time using the Date and Time functions. FormatDateTime will provide you with a date and time format that is culture neutral that you can analyze.

You can get the result in VBScript using WScript.Echo from the script and call it like this from the package:

 for /f "delims=" %%x in ('cscript /nologo foo.vbs') do set result=%%x 

Then the %result% variable contains everything that VBScript had as output in its first line.

+1
source share

The CoreUtils project for Windows http://gnuwin32.sourceforge.net/packages/coreutils.htm has a date command that provides you with the same features as Linux.

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

For all available options, enter:

 gnudate --help 

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

 Sun 10 apr 2016 21:52:35 

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

 1460325461 

The following Dos batch file shows the use of gnudate. You will need to double the % value 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 on a Linux virtual machine.

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

+1
source share

All Articles