Go Down

Topic: time functions such as hourFormat12() (Read 1 time) previous topic - next topic

mxing

Hey HazardsMind, thanks!
actually I have something going that is similar to your suggestion.  Each time the button is pushed a variable increases by one but won't go over 12.

My issue is that I'm not sure how to then insert that value into hourFormat12(). 

Jimmy60, thank you too!
I was wonder if I would need to convert the entered time into Unix time and then use setTime(pctime).  In fact I did try something similar, I did something like:

void processSyncMessage() {
  pctime = 1356508790;
  setTime(pctime);
...

but for some reason the time in that didn't get into hourFormat12(), so that when it is supposed to go to the LCD nothing happened:

Code: [Select]

  lcd.setCursor(0, 2);
  lcd.print("Time: ");

  lcd.print(hourFormat12());
  printDigits(minute());
  printDigits(second());
 
    if (isAM())
  {
    lcd.print(" AM ");
  }
  if (isPM())
  {
    lcd.print(" PM ");
  }
 
  lcd.setCursor(0, 3);
  lcd.print("Date: ");
  lcd.print(day());
  lcd.print("/");
  lcd.print(month());
  lcd.print("/");
  lcd.print(year());

Code: [Select]




Jimmy60

Unix time is in seconds. I took a look at the time library header and it appears that hourFormat12() should return the hour in a 12 hour format (as opposed to hour() which is 24) it also appears to have an overload to return the hour when passed Unix time.

Have you tried the hour() method to see if that works?

Personally, I only ever use a 24 hour clock.

mxing

Hey Jimmy,
I agree with what you say regarding hourFormat12(), I get the 12hr format when I input the Unix time number in seconds.  And yes the hour() simply gives the military format, which is what I had before playing with hourFormat12().   But you see both of these require the Unix seconds as input (I believe).

What I'm trying to do is pass to hourFormat12() for example, say the number 7, for the hour.   Do you think that's possible or do you suggest converting what I input with the buttons, to Unix time seconds?

thanks again for your replies.
tim

Docedison

You can convert UNIX time to whatever with the time lib but
Quote
hourFormat12()
is used to return the 12 hour format for the Time library which is basically the code for a digital alarm clock that runs on an Arduino. I am currently using it in two of my projects. Your processing code could easily pass the time to it.
My reason for using it is that it is pretty much in the background as far as it's operation goes and allows me to have a clock without the bother of writing one and at the same 'time' handle screen refreshing, a touch keypad and some other devices...

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

mxing

Thanks Bob,
your alarm clock project, do you set the time with buttons or Unix time?

thx
tim


Go Up