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 144 views
1 answer 122 views
1 answer 176 views
1 answer 76 views
1 answer 187 views
1 answer 191 views
...