2

I want to write a time converter in windows batch script. It is going to be used when I want to set an appointment (I want to put it in my email content). The script should be able to print out the following lines (output to clipboard ideally, file is okay too):

Beijing (China) TUE, January 16, 2016 at 8:00 AM
Seattle (U.S.A) MON, January 15, 2016 at 4:00 PM

First of all, I found the windows date utility can print out the date and time nicely and I want to take advantage of it. Then, for the current time, I found using

tzutil /s "Pacific Standard Time_dstoff"
tzutil /s "China Standard Time"

would be a easy way to get the date and then print it out. It changes the system time to Pacific time and then change it back to China Standard Time.

However, since I do NOT have the root right to change the system time, I am wondering what is the best way to do the time converting for any given new appointment datetime. Say I want to setup an appointment on 2/19/2016 08:00 Beijing time, how could I easily get the following lines into my clipboard?

Beijing (China) TUE, February 19, 2016 at 8:00 AM
Seattle (U.S.A) MON, February 18, 2016 at 4:00 PM
Daniel
  • 2,576
  • 7
  • 37
  • 51
  • Dates in batch are hell because nothing understands them other than as arbitrary strings or numbers. If I had to do this, I'd use VBScript or PowerShell, with a strong preference for the latter. – Bacon Bits Mar 17 '15 at 20:25
  • @BaconBits, OKay, then how please? – Daniel Mar 18 '15 at 00:26
  • I'd probably start with something like [this](http://stackoverflow.com/a/20101121/696808). Look on [MSDN](https://msdn.microsoft.com/en-us/library/system.timezoneinfo%28v=vs.110%29.aspx) for doc on the class. Enumerate the time zones with `[System.TimeZoneInfo]::GetSystemTimeZones()`. If you haven't got Powershell 3 or 4, however, it may be painful. I don't believe all those classes are exposed. – Bacon Bits Mar 18 '15 at 15:31

1 Answers1

1

Would a language like Python work?

from datetime import datetime
from datetime import timedelta

now = datetime.now()

# This assumes Beijing is the local timezone
print(now.strftime('Beijing (China) %a, %B %d at %I:%M %p'))

# Seattle is 15 hours behind Beijing
now -= timedelta(hours = 15)
print(now.strftime('Seattle (U.S.A) %a, %B %d at %I:%M %p'))
Matt Johnson
  • 368
  • 2
  • 10