You are not logged in.
This script gives the time in GMT
https://ss64.com/nt/syntax-gmt.html
Obviously just add or subtract a number from this to get the time in any other time zone
Offline
What if the time offset is fractional like 3.5 hrs can someone fix the script to account for this?
can it tell if the offset is plus or minus?
Offline
What if the time offset is fractional like 3.5 hrs can someone fix the script to account for this?
can it tell if the offset is plus or minus?
Yes, it will return a negative number if you're located to the east of the Prime Meridian.
Offline
It's correct?
Local time: 00:28
GMT time: -2:28
Offline
Really it would be better to extend this so that it returns both data and time, you could then treat negative times differently - subtract 1 from the date and add 24 hours, so -2:28 would then become 22:28
Offline
The Win32_UTCTime WMI class already contains the GMT date and time, so frankly I don’t see the need for gmt.cmd?
[revoked example]
Last edited by Pyprohly (10 Feb 2018 09:32)
Offline
Because it wasn't available in 2006 when the topic was first created.
Offline
I have now updated the page https://ss64.com/nt/syntax-gmt.html to use wmic path Win32_UTCTime
In PowerShell, this can be done with just:
$mydtm = Get-Date
$mydtm.ToUniversalTime()
Offline
Fair enough, Shadow Man.
Regarding the updated script, the need for that caret symbol in the FOR /F loops look questionable…
Offline
Fair enough, Shadow Man.
Regarding the updated script, the need for that caret symbol in the FOR /F loops look questionable…
Try it without and see what happens!
consider why this fails:
@echo off
setlocal EnableDelayedExpansion
for /f %%G in ('echo Hi ^& set _snark=Hello') do (echo [!_snark!])
C:\batch>demo.cmd
Environment variable _snark Hello not defined
[]
The important thing here is that the variable _snark is not available in the DO clause, even with EnableDelayedExpansion, so the commands we run between the ' ' are running in a subshell, and thats why we need to escape the & and | characters if we want them to be ignored by the current shell and just passed to the subshell.
Offline
Oh, I didn’t even notice that caret symbol because it’s in such a routine position. I’m referring to the other caret symbol, the one in the options part: “delims=^=”.
The equals symbol doesn’t need escaping and the caret symbol isn’t escaping anything there.
Offline
Ah yes, good point - I'll fix that now.
Thanks
Offline