Raspberry Pi and settings of datetime

Another annoying missed feature is how to set properly the datetime on our device. In this article I try to explain how to do that from a PowerShell commands.

First of all:

open PowerShell with Administrator’s rights and type the first command

[code lang=”csharp”]net start winrm[/code]

IoTSD_1

this command will enable the “winrm” that allows our PC to communicate with RPi. Now we have to login with the command

[code lang=”csharp”]Enter-PSSession -ComputerName minwinpc -Credential minwinpc\Administrator[/code]

where “miniwinpc” is the name of our RPi. If you have changed, change this line of command. So, now a window will appear and asks us the password to access and press “Ok” to continue.

PowerShellPwd

After a while, our prompt will appear and now we can give commands directly to RPi. To change the date we have to change the geographic area in this manner:

[code lang=”csharp”]tzutil /s "W. Europe Standard Time"[/code]

This command line will change the location of the time to West Europe time. The command “tzutil” (Time Zone Utility) have a simple syntax:

the command line  is “TZUTIL /g | /l | /s “TimeZoneValue[_dstoff]” | /?”

Parameters:
/? Displays usage information.

/g Displays the current time zone ID.

/s TimeZoneID[_dstoff]
Sets the current time zone using the specified time zone ID.
The _dstoff suffix disables Daylight Saving Time adjustments
for the time zone (where applicable).

/l Lists all valid time zone IDs and display names. The output will
be:
<display name>
<time zone ID>

In example we could set the Samoa Standard Time with this command:

[code lang=”csharp”]tzutil /s "Samoa Standard Time"[/code]

now we can ask the system to show us what is the current time zone set on device with this command:

[code lang=”csharp”]tzutil /g[/code]

and finally we can switch off the Daylight Saving Time in Samoa time zone with this command

[code lang=”csharp”]tzutil /s "Samoa Standard Time_dstoff"[/code]

There is a list of all time zone allowed and I list it here

Name of Time Zone Time
Dateline Standard Time (GMT-12:00) International Date Line West
Samoa Standard Time (GMT-11:00) Midway Island, Samoa
Hawaiian Standard Time (GMT-10:00) Hawaii
Alaskan Standard Time (GMT-09:00) Alaska
Pacific Standard Time (GMT-08:00) Pacific Time (US and Canada); Tijuana
Mountain Standard Time (GMT-07:00) Mountain Time (US and Canada)
Mexico Standard Time 2 (GMT-07:00) Chihuahua, La Paz, Mazatlan
U.S. Mountain Standard Time (GMT-07:00) Arizona
Central Standard Time (GMT-06:00) Central Time (US and Canada
Canada Central Standard Time (GMT-06:00) Saskatchewan
Mexico Standard Time (GMT-06:00) Guadalajara, Mexico City, Monterrey
Central America Standard Time (GMT-06:00) Central America
Eastern Standard Time (GMT-05:00) Eastern Time (US and Canada)
U.S. Eastern Standard Time (GMT-05:00) Indiana (East)
S.A. Pacific Standard Time (GMT-05:00) Bogota, Lima, Quito
Atlantic Standard Time (GMT-04:00) Atlantic Time (Canada)
S.A. Western Standard Time (GMT-04:00) Caracas, La Paz
Pacific S.A. Standard Time (GMT-04:00) Santiago
Newfoundland and Labrador Standard Time (GMT-03:30) Newfoundland and Labrador
E. South America Standard Time (GMT-03:00) Brasilia
S.A. Eastern Standard Time (GMT-03:00) Buenos Aires, Georgetown
Greenland Standard Time (GMT-03:00) Greenland
Mid-Atlantic Standard Time (GMT-02:00) Mid-Atlantic
Azores Standard Time (GMT-01:00) Azores
Cape Verde Standard Time (GMT-01:00) Cape Verde Islands
GMT Standard Time (GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London
Greenwich Standard Time (GMT) Casablanca, Monrovia
Central Europe Standard Time (GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
Central European Standard Time (GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb
Romance Standard Time (GMT+01:00) Brussels, Copenhagen, Madrid, Paris
W. Europe Standard Time (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
W. Central Africa Standard Time (GMT+01:00) West Central Africa
E. Europe Standard Time (GMT+02:00) Bucharest
Egypt Standard Time (GMT+02:00) Cairo
FLE Standard Time (GMT+02:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius
GTB Standard Time (GMT+02:00) Athens, Istanbul, Minsk
Israel Standard Time (GMT+02:00) Jerusalem
South Africa Standard Time (GMT+02:00) Harare, Pretoria
Russian Standard Time (GMT+03:00) Moscow, St. Petersburg, Volgograd
Arab Standard Time (GMT+03:00) Kuwait, Riyadh
E. Africa Standard Time (GMT+03:00) Nairobi
Arabic Standard Time (GMT+03:00) Baghdad
Iran Standard Time (GMT+03:30) Tehran
Arabian Standard Time (GMT+04:00) Abu Dhabi, Muscat
Caucasus Standard Time (GMT+04:00) Baku, Tbilisi, Yerevan
Transitional Islamic State of Afghanistan Standard Time (GMT+04:30) Kabul
Ekaterinburg Standard Time (GMT+05:00) Ekaterinburg
West Asia Standard Time (GMT+05:00) Islamabad, Karachi, Tashkent
India Standard Time (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi
Nepal Standard Time (GMT+05:45) Kathmandu
Central Asia Standard Time (GMT+06:00) Astana, Dhaka
Sri Lanka Standard Time (GMT+06:00) Sri Jayawardenepura
N. Central Asia Standard Time (GMT+06:00) Almaty, Novosibirsk
Myanmar Standard Time (GMT+06:30) Yangon Rangoon
S.E. Asia Standard Time (GMT+07:00) Bangkok, Hanoi, Jakarta
North Asia Standard Time (GMT+07:00) Krasnoyarsk
China Standard Time (GMT+08:00) Beijing, Chongqing, Hong Kong SAR, Urumqi
Singapore Standard Time (GMT+08:00) Kuala Lumpur, Singapore
Taipei Standard Time (GMT+08:00) Taipei
W. Australia Standard Time (GMT+08:00) Perth
North Asia East Standard Time (GMT+08:00) Irkutsk, Ulaanbaatar
Korea Standard Time (GMT+09:00) Seoul
Tokyo Standard Time (GMT+09:00) Osaka, Sapporo, Tokyo
Yakutsk Standard Time (GMT+09:00) Yakutsk
A.U.S. Central Standard Time (GMT+09:30) Darwin
Cen. Australia Standard Time (GMT+09:30) Adelaide
A.U.S. Eastern Standard Time (GMT+10:00) Canberra, Melbourne, Sydney
E. Australia Standard Time (GMT+10:00) Brisbane
Tasmania Standard Time (GMT+10:00) Hobart
Vladivostok Standard Time (GMT+10:00) Vladivostok
West Pacific Standard Time (GMT+10:00) Guam, Port Moresby
Central Pacific Standard Time (GMT+11:00) Magadan, Solomon Islands, New Caledonia
Fiji Islands Standard Time (GMT+12:00) Fiji Islands, Kamchatka, Marshall Islands
New Zealand Standard Time (GMT+12:00) Auckland, Wellington
Tonga Standard Time (GMT+13:00) Nuku’alofa

What we have to write is the left column.

Ok, now we set the time zone and we have to sincronize the watch with the command

[code lang=”csharp”]w32tm /resync
[/code]

Sometime it’s possible that the time set is not correct, it depends on the server sync or other minor factors. To set manually the date and the time use the command

[code lang=”csharp”]set-date "2016/08/20 21:59"
[/code]

Now our RPi is ready and in sync, it’s time to switch off our PowerShell, but we have to do that in clear mode.

[code lang=”csharp”]w32tm /resync
Exit-PSSession
net stop winrm
exit
[/code]

Ok, now we’re logged off from RPi and every connections are closed. If the time is already not in sync, reboot the RPi.

Enjoy!!!