is it possible to get the current timezone
and if enabled the daylight saving offset
from/within a batch file?
Andi
You could use w32tm.exe.
143} How do I get the current time zone in a script?
http://www.netikka.net/tsneti/info/tscmd143.htm
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
Alas, #143 is in terminological error.
Time zones, by definition. are geographically fixed and do not move with
the season. Helsinki, etc., remain firmly fixed in the +2 time zone,
all year round. The codes give the offsets from UTC, and only in Winter
(if there is Summer Time at the location) does that correspond with the
Time Zone.
Win XP : wmic OS Get CurrentTimeZone
clearly gives (Local Time - UTC) in minutes.
Win XP : w32tm / tz
is less clear to me - you have the advantage that your Winter Offset,
Summer Offset, and clock change are all different values, 120 180 60.
WinXP : systeminfo | findstr /b "Time Zone:"
does get the zone, expressed as a time offset.
The best way, easy enough in JavaScript, to get the true Time Zone is to
set January 1 and July 1, get both Offsets, choose whichever of the two
is larger as being Winter Time, and use that. But I may mean smaller.
Or to use W32tm /tz and read the "Standard Name:" line. The names
themselves are Microsoft's view, and outside the USA do not necessarily
correspond with reality.
Since the OP is posting from .de, I expect that he does want the real
time zone; but "daylight saving" is not English for "Sommerzeit"
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
> Alas, #143 is in terminological error.
John, the item delves into whatever information the XP computer offers
under the hood. The interpretation of the terminology and the usage of
the results is up to the user, since mine is a scripting FAQ, not a
calendar intricacies treatise. But thank you for the refinements. Always
welcome.
>> [...]
> Time zones, by definition. are geographically fixed and do not move with
> the season. Helsinki, etc., remain firmly fixed in the +2 time zone,
> all year round. The codes give the offsets from UTC, and only in Winter
> (if there is Summer Time at the location) does that correspond with the
> Time Zone.
Really strange. I tested all five scripts at:
http://www.netikka.net/tsneti/info/tscmd143.htm
saved them to test1.bat, test2.bat, etc., and run
them with a helper batchfile named testrun.bat
---snip---
@echo off
REM short date format of computer is set to YYYY-MM-DD (ISO format)
for /f "tokens=1-3 delims=./-" %%f in ("%date%") do (
set TODAY=%%f-%%g-%%h
)
date 2009-01-01
echo date 2009-01-01 (winter)
call %1
date 2009-06-01
echo date 2009-06-01 (summer)
call %1
date %TODAY%
---snap---
and run this batch with each batch/script file in an admin
elevated console (vista) and got these outputs
---snip---
D:\timezone>testrun.bat test1.bat
date 2009-01-01 (winter)
Bias: -60 minutes
UTC+(1.0)
date 2009-06-01 (summer)
Bias: -60 minutes
UTC+(1.0)
D:\timezone>testrun.bat test2.bat
date 2009-01-01 (winter)
CurrentTimeZone: minutes
date 2009-06-01 (summer)
CurrentTimeZone: minutes
D:\timezone>testrun.bat test3.bat
date 2009-01-01 (winter)
(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
GMT+01:00
date 2009-06-01 (summer)
(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
GMT+01:00
D:\timezone>testrun.bat test4.bat
date 2009-01-01 (winter)
TZbias=Input
date 2009-06-01 (summer)
TZbias=Input
D:\timezone>testrun.bat test5.bat
date 2009-01-01 (winter)
TZbias=60
TZdaylightBias=-60
date 2009-06-01 (summer)
TZbias=60
TZdaylightBias=-60
---snap---
but all five files are not very useful for me, bcause
I can't see if "summertime" (Sommerzeit) is set or not.
btw: second and fourth script are very unuseful in vista ;-)
anyway, can't see differnces between the summer and winter
> Win XP : wmic OS Get CurrentTimeZone
> clearly gives (Local Time - UTC) in minutes.
this looks good to me, but have a strange problem with unicode
or codepage I think. On my vista box. At the console I have
the following output:
---snip---
D:\timezone>testrun.bat test10.bat
date 2009-01-01 (winter)
CurrentTimeZone
60
date 2009-06-01 (summer)
CurrentTimeZone
120
---snap---
looks good and there is a diffrence between summer and winter
but how can I use this vals to differentiate and use them
in a batchfile? for ex. how can I put the 60 in a envvar?
Or how can I build the diffrence ant put that in a var.
then I could use something like:
if ."%DIFF%"==."0" goto ...
or
if ."%DIFF%"==."60" set foo=bar
First I tried to pipe the ouptut to a text file but that
file looks very strange (looks like a binary file) :-( How can
I avoid this (don't know what exact) unicode/multibyte/codepage
issue?
if I type out the piped text file "D:\timezoen>type test.txt" I get
---snip---
date 2009-01-01 (winter)
u r r e n t T i m e Z o n e
6 0
date 2009-06-01 (summer)
u r r e n t T i m e Z o n e
1 2 0
---snap---
hmmm ???
> Win XP : w32tm / tz
> is less clear to me - you have the advantage that your Winter Offset,
> Summer Offset, and clock change are all different values, 120 180 60.
>
> WinXP : systeminfo | findstr /b "Time Zone:"
> does get the zone, expressed as a time offset.
>
>
> The best way, easy enough in JavaScript, to get the true Time Zone is to
> set January 1 and July 1, get both Offsets, choose whichever of the two
> is larger as being Winter Time, and use that. But I may mean smaller.
How would you do that?
> Or to use W32tm /tz and read the "Standard Name:" line. The names
> themselves are Microsoft's view, and outside the USA do not necessarily
> correspond with reality.
with that I get (not with the helper batch file. Just the normal console
---snip---
D:\adm\timezone>w32tm /tz
Time zone: Current:TIME_ZONE_ID_DAYLIGHT Bias: -60min (UTC=LocalTime+Bias)
[Standard Name:"W. Europe Standard Time" Bias:0min Date:(M:10 D:5 DoW:0)]
[Daylight Name:"W. Europe Daylight Time" Bias:-60min Date:(M:3 D:5 DoW:0)]
---snap---
but in the "Standard Name:" line I can't see if it is
"Sommerzeit". How can I determine the "Sommerzeit"
And what is the meaning of M:XX and D:X? DoW can be "Day of Week"
but today its Sutarday (usually in Germany the sixth day, and seventh day
in english speaking countries) and it is not the 0. or 5. day like the D:X
val shows. And it is not the month 10. or 3. it is (ISO format: 2009-05-02)
So D:X can mean the month?
Really strange.
> Since the OP is posting from .de, I expect that he does want the real
> time zone; but "daylight saving" is not English for "Sommerzeit"
I mean the "Sommerzeit". Think in english it is named
"daylight saving" isn't it?
Andi
Saturday is the seventh day in American-speaking countries (they ignore
Genesis Chapter 2 verses 2,3). British business uses sixth, in
agreement with ISO 8601. Outside business we don't need day-of-week
numbering, but we use "weekend" as you presumably use "wochenende".
Calendars and diaries here used to start the week on Sunday; but now
they mostly use Monday.
> and it is not the 0. or 5. day like the D:X
>val shows. And it is not the month 10. or 3. it is (ISO format: 2009-05-02)
>So D:X can mean the month?
>Really strange.
They will mean that the change TO that time is in the month M (of
1..12), on day-of-week DoW (0 = Sunday, since they believe day 0 to be
the first day of the week), and on the D'th instance of that day-of-week
in that month, where 5 means last. That expresses the change-dates used
throughout the Brussels Empire and the ex-Soviet one. It is a subset of
TZ notation; TZ also gives the time-of-change (as what the clocks are
changed from, rather than doing it all sensibly in UTC), but MS didn't
bother to include that.
>> Since the OP is posting from .de, I expect that he does want the real
>> time zone; but "daylight saving" is not English for "Sommerzeit"
>
>I mean the "Sommerzeit". Think in english it is named
>"daylight saving" isn't it?
No. In English it is "Summer Time". Across the Atlantic they use a
different language which they incorrectly call English. Many of their
words are the same (perhaps mis-spelt); somewhat fewer have exactly the
same meaning(s).
One can use, in Windows, Windows Script Host (WSH) to execute
JavaScript, a language which is standardised by ISO/IEC 16262.
JavaScript can determine the Winter and Summer offsets, and the change
date/times. WSH+JS can be used to set environment variables. I don't
think I have an example of exactly what you want on my site; but I have
parts which could be put together.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.