Languages

Menu
Sites
Language
Display time as AM/PM format

How can I use the method below

tizen.time.getCurrentDateTime()

to display time in AM/PM format as opposed to military time?

 

Thanks!

Edited by: Rich Mabb on 20 Mar, 2017
View Selected Answer

Responses

4 Replies
Iqbal Hossain

 

// Gets the time format, e.g. "h:m:s ap".
 var timeFormat = tizen.time.getTimeFormat();

 console.log(timeFormat);

These expressions may be used in the returned string:

  • "h" = hours (0 to 23 or 1 to 12 if AM/PM display)
  • "m" = minutes (0 to 59)
  • "s" = seconds (0 to 59)
  • "ap" = AM/PM display

Examples of string formats include: "h:m:s ap", "h:m:s".

Follow this => https://developer.tizen.org/development/api-references/web-application?redirect=/dev-guide/2.4/org.tizen.web.apireference/html/device_api/mobile/tizen/time.html#TimeUtil::getTimeFormat

Rich Mabb

 

var datetime = tizen.time.getCurrentDateTime(),
        hour = datetime.getHours(),
        minutes = datetime.getMinutes();
        
    console.log("current time is: " +hour+":"+minutes);

 

The code above displays the time as: 16:21

How can I convert this to display as" 4:21 PM

 

Any help greatly appreciated!

Mark as answer
Iqbal Hossain

If you haven't get any API till now to do this, you can use this to meet your requirement

        var datetime = tizen.time.getCurrentDateTime(),
        hour = datetime.getHours(),
        minutes = datetime.getMinutes();
        var amPm= 'AM';
        if(hour >=13 && hour <=23){
            amPm= 'PM';
            hour= hour-12;
        }
        if(hour == 12){
            amPm= 'PM';
        }
        if(hour === 0){
            hour=12;
        }
        console.log("current time is: " +hour+":"+minutes+ amPm);

 

Rich Mabb

Thank you Iqba!