Dave's Brain

Browse - Programming Tips - How can I display the time with am/pm?

Date: 2014apr28
Language: Java
Level: Beginner

Q.  How can I display the time with am/pm?

A.

private static SimpleDateFormat fmtTime = new SimpleDateFormat("h:mma"); // h = hour without leading zero (because that's ugly) // mm = 2 digit minute // a = AM or PM (I make it lowercase since that looks nicer) String getTime() { Date date = new Date(); return fmtDate.format(date).toLowerCase(); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.