Solved

Batch File: Fix date and time with Time Zone

Posted on 2014-01-10
7
1,265 Views
Last Modified: 2014-01-10
Hi there,

I have a date, and a time at 0GMT.

To need a batch file to change them according to -5GMT

For example:
2014-01-10 00:44:34  -> 2014-01-09 19:44:34
2014-02-01 00:44:34 -> 2014-01-31 19:44:34
2014-02-01 20:44:34 -> 2014-02-01 15:44:34

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:CorinTack
ID: 39771522
Add the following to a batch file:

TZUTIL /s "Eastern Standard Time"
0
 
LVL 10

Author Comment

by:ReneGe
ID: 39771552
hey CorinTack, thank for your prompt reply.

I don't need to change the time zone of my PC.

For example:

@ECHO OFF
CALL :TimeZone "2014-01-10 00:44:34"
ECHO %NewDate% %NewTime%
PAUSE
EXIT

:TimeZone
REM Code nere
EXIT /b
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39772103
You might think of this as "cheating" but it's a very useful approach in BAT scripts.

@echo off
REM Initialization
echo d=DateAdd("h",CInt(Wscript.Arguments.Item(1)),CDate(Wscript.Arguments.Item(0)))>"%TEMP%\_t.vbs"
echo Wscript.Echo Year(d)^&"-"^&Right("0"^&Month(d),2)^&"-"^&Right("0"^&Day(d),2)^&" "^&Right("0"^&Hour(d),2)^&":"^&Right("0"^&Minute(d),2)^&":"^&Right("0"^&Second(d),2)>>"%TEMP%\_t.vbs"

REM Main logic
call :tzAdjust "2014-01-10 00:44:34" "-5"
echo Expected: 2014-01-09 19:44:34
echo tzAdjust: %tzAdjust%
echo.
call :tzAdjust "2014-02-01 00:44:34" "-5"
echo Expected: 2014-01-31 19:44:34
echo tzAdjust: %tzAdjust%
echo.
call :tzAdjust "2014-02-01 20:44:34" "-5"
echo Expected: 2014-02-01 15:44:34
echo tzAdjust: %tzAdjust%

REM Cleanup
del "%TEMP%\_t.vbs"
exit /b

:tzAdjust [date-time] [hours-offset]
  for /F "tokens=*" %%A in ('cscript //nologo "%TEMP%\_t.vbs" "%~1" "%~2"') do set tzAdjust=%%A
  exit /b

Open in new window

~bp
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Author Comment

by:ReneGe
ID: 39772207
Hey buddy, its been a while :)

here is my output:
Expected: 2014-01-09 19:44:34
tzAdjust: 2014-01-09 19:44:34

Expected: 2014-01-31 19:44:34
tzAdjust: 2014-01-31 19:44:34

Expected: 2014-02-01 15:44:34
tzAdjust: 2014-02-01 15:44:34

Cheers
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 39772746
Correct, that's the proper output, as you requested.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 39772813
Whats wrong with me???

Thanks Bill :)
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 39772866
Welcome Rene.

~bp
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now