How to add AM/PM to time in Java

1 Answer

0 votes
package javaapplication1;

import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        Date date = new Date();
   
        // add AM/PM using 'a' format
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss a");
     
        System.out.println(sdf.format(date));
    }  
}
   
/*
   
run:
   
18:31:36 PM
   
*/

 



answered Oct 29, 2016 by avibootz

Related questions

2 answers 155 views
1 answer 134 views
1 answer 187 views
1 answer 89 views
1 answer 203 views
1 answer 205 views
...