avatar

Member

rusell

How To Format Time With Am/pm In Java

(Feb 18 2017 at 08:51am)

/* Add AM/PM to time using
SimpleDateFormat This example shows how
to format time to have a AM/PM text
using Java SimpleDateFormat class. */
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args)
{
//create Date object
Date date = new Date();
//formatting time to have AM/PM text
using 'a' format
String strDateFormat = "HH:mm:ss a";
SimpleDateFormat sdf = new
SimpleDateFormat(strDateFormat);
System.out.println("Current Time: " +
sdf.format(date)); }}

[1K views]


You may also Like:

Quick reply


add files