Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current time in HH:MM:SS am/pm format?

How can I obtain the current time in HH:MM:SS am/pm format?

like image 351
NSExplorer Avatar asked Jan 17 '11 16:01

NSExplorer


People also ask

What is HH MM AM PM format?

There are two patterns that we can use in SimpleDateFormat to display time. Pattern “hh:mm aa” and “HH:mm aa”, here HH is used for 24 hour format without AM/PM and the hh is used for 12 hour format with AM/PM. aa – AM/PM marker. In this example we are displaying current date and time with AM/PM marker.

How do I show time in AM PM in SQL?

Get time format of datetime in sql. ORDER BY expr1 ; SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3)-->it gives you a am/pm.

How do you display JavaScript datetime in 12 hour AM PM format?

To make formatting a date-time to AM/PM format easier, we can use the toLocaleString method. For instance, we can write: const str = new Date(2021, 1, 1). toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true }) console.


1 Answers

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mm:ss a"]; NSLog(@"Current Date: %@", [formatter stringFromDate:[NSDate date]]); [formatter release]; 

The format of the string in setDateFormat is based on ISO-8601, http://en.wikipedia.org/wiki/ISO_8601#Dates

Swift 3 Version:

let formatter = DateFormatter() formatter.dateFormat = "hh:mm:ss a" print("Current date: \(formatter.string(from: Date()))") // -> Current date: 08:48:48 PM 

There's also a new site since this original answer that helps writing these format strings. Aptly named... http://nsdateformatter.com

like image 65
Chris Wagner Avatar answered Sep 22 '22 18:09

Chris Wagner