Hope someone can help with this. I am looking for a function I can use in a Windows batch file that will turn the clock back 3 hours from its "current" setting.
Here are the requirements I foresee:
- parse the "current" time (i.e. 2:42 PM)
- calculate "current" time minus 3 hours (i.e. 11:42 AM if current time as 2:42 PM) and set that value as "new time"
- Change the "current time" to "new time".
- account for rolling back the date by a day if the time change would set it a time on previous day (i.e. Rolling back if the current time is between 12 am and 3 am requires changing the date back a day as well)
Thanks,
Mike
need function to turn clock back by 3 hours
Moderator: DosItHelp
Re: need function to turn clock back by 3 hours
Can I ask what the purpose is for this task?
Re: need function to turn clock back by 3 hours
Here is the background: I have a batch file that customizes newly installed copies of the Windows OS. Part of the batch file sets the timezone to EST. When this happens it advances the clock by 3 hours because Windows defaults to PST. Before you say anything; I know I could develop an automated install of Windows that uses the correct timezone. At this time though I'm not ready to do that so I just want to address this issue through batch file. Thats the purpose of the request.
Mike
Mike
Re: need function to turn clock back by 3 hours
Have a look at a batch script called GetTimeStamp.bat written by dbenham
viewtopic.php?p=44148#p44148
It has 7 billion methods of calculating time/date
viewtopic.php?p=44148#p44148
It has 7 billion methods of calculating time/date
Re: need function to turn clock back by 3 hours
MCP wrote:Foxidrive,
Thanks for the link. I'm sure someone could probably use that script to code part of what I'm trying to accomplish but for me it is beyond my current experience level to understand it and then write the additional code required to use it in the way I need in any kind of timely manner.
I'm really looking for something a bit more "turn key" that I can just copy and plug-in to my batch file. If you have any additional examples that are a little closer to my requirements or can put together something that specifically targets what I need then that would be fantastic.
Mike
It doesn't get much more turnkey than getTimestamp.bat.
You need to know the date and time format used by your locale. For me I need mm-dd-yyyy and hh:mm:ss.ff, where hh is in 24 hour format, and .ff is optional fractional seconds. Also, you must be running as administrator if you want to modify your computer's system date/time.
Code: Select all
for /f "tokens=1,2" %%A in (
'gettimestamp /oh -3 /f "{mm}-{dd}-{yyyy} {hh}:{nn}:{ss}"'
) do date %%A & time %%B
Dave Benham