Get AM/PM from widget


I am trying to get values from Time Input Widget

t.getStartMinute() ;

With these i can get the start time from the widget.
Is there a way to get AM or PM info from the widget ? like t.getAM/PM();

Hello Blynkers !!

I dont have any replies on this topic :roll_eyes: does that mean there is no such option available ?
Is there any way to read the time along with AM or PM ?

I’m not really clear what you’re trying to achieve here, which is why I didn’t respond earlier.

The Time Input widget has the ability to allow the choice between HH:MM:SS and HH:MM:SS AM/PM time input formats.
This only changes the UI in the app. If you want to select a start time of 7pm then you have to choose 19:00 in HH:MM:SS format and 7:00 + PM in HH:MM:SS AM/PM format.

However, this has no effect on the format of data that is received in the app. You will get a start time of 68400 seconds in each case.

param[0] is the start time in seconds, so working-out whether a time is AM or PM is simply a case of working-out whether it’s before or after midday, which is 43200 seconds past midnight.
This bit of (untested) code demonstrates how you can do it…

  long startTimeInSecs = param[0].asLong();
  String Start_AM_PM_Indicator;
  if (startTimeInSecs < 43200)
    Start_AM_PM_Indicator = "AM";
   Start_AM_PM_Indicator = "PM";
  Serial.print("Start time is ");


1 Like

Sorry for the late reply.
Actually i using DS3231 RTC module for time keeping. It was giving time in 12hr format with AM and PM. So i was trying to compare with the the time we set from the Time input widget.

After reading your reply i changed the format to 24hr in the RTC and now i have it working.

Thank you for giving the quick and easy method to follow. :clap:

1 Like

Why do you have a DS3231? Blynk has a perfect RTC widget

Yes. I was using Blynk RTC from past many years.
But i have internet connection dropping every now and then. But i had Time.h lib to keep the track of the time, but if the esp reboots when there is no internet i have no way to determine the current time.
So i ended up using DS3231.

Can you tell me if there are any other trick or ideas to overcome this problem?

The RTC works even if internet has dropped. The RTC syncs with server at set timeset by you setSyncInterval(86400);

You are right. This works only when the internet is available, it syncs the current time from the internet and keeps track of the time even if the internet is down… Now lets say the internet is down and the device reboots !!

Now the device cannot have the current time.

Why would the device reboot? If your code is written correctly the device continues to work as normal. Reboot occurs only at loss of power. All my projects carry on working as normal if the internet drops. If there is a reboot for some reason ie loss of power then the whole sketch reboots including the void setup

Power cut. :man_facepalming: :neutral_face:

you mean power cut and no internet?

YES. You got it right.