Bbuschke
Posts: 16
Joined: Tue Jan 31, 2017 4:02 am

time format

Tue Feb 07, 2017 10:03 pm

I connected at 16x2 lcd to display time but it only shows time in 24hr format and i want 12 hr format. Any idea how i can change the pi's time format?

User avatar
CarlRJ
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: time format

Tue Feb 07, 2017 10:09 pm

As with all Unix systems, the Pi's time format is seconds past midnight January 1st 1970, UTC. If you're seeing the time in some more human readable format, that is because of the program that you're running. That program is what needs changing.

User avatar
DougieLawson
Posts: 36557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: time format

Tue Feb 07, 2017 10:34 pm

It's the difference between

Code: Select all

  time (&rawtime);
  timeinfo = localtime (&rawtime);

  strftime (time_of_day,16,"%T %b,%d",timeinfo);
and

Code: Select all

  time (&rawtime);
  timeinfo = localtime (&rawtime);

  strftime (time_of_day,16,"%R %b,%d",timeinfo);
and

Code: Select all

  time (&rawtime);
  timeinfo = localtime (&rawtime);

  strftime (time_of_day,16,"%r %b,%d",timeinfo);
Most programming languages use those strftime() strings to choose the time/date formats.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “General discussion”