I have date and time input by user in the format DD-MM-YYYY HH:MM:SS. For example: 27-01-2019 12:47:00 PM IST
Please help me how to set the date, time and time zone of raspberry pi from its command line interface.
I have date and time input by user in the format DD-MM-YYYY HH:MM:SS. For example: 27-01-2019 12:47:00 PM IST
Please help me how to set the date, time and time zone of raspberry pi from its command line interface.
This question appears to be off-topic. The users who voted to close gave this specific reason:
A programming language agnostic way to do this would be to call the date --set="STRING"
command to set the system clock and then hwclock --systohc --utc
command to set the RTC. How you do this from your code depends on the language you use.
From the manual page for date
it looks like you can drop your string as-is into the command but you might want to check it on the actual version of date
shipped on your Pi:
Date String
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
Use the date
utility.
If you really MUST you could build an application around this. Python has date, time and datetime modules.
Frankly you would be better to spend $2 on a RTC module. We used to do things like this in 1975!
hwclock
. You would have been better to have asked your real question rather than posing an XY problem
– Milliways
Jan 27 at 12:04