Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,252 questions

18,038 answers

573 users

How to use SimpleDateFormat to format and parse date and time in Java

4 Answers

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

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();  
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");  
        String s = formatter.format(date);  
        
        System.out.println(s);  
    } 
}



/*
run:

23/05/2020

*/

 




answered May 23 by avibootz
0 votes
import java.text.SimpleDateFormat;  
import java.util.Date;  

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();  
        SimpleDateFormat formatter = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");  
        String s = formatter.format(date);  
        
        System.out.println(s);  
    } 
}



/*
run:

23-5-2020 07:43:07

*/

 




answered May 23 by avibootz
0 votes
import java.text.SimpleDateFormat;  
import java.util.Date;  

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();  
        SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy zzzz");  
        String s = formatter.format(date);  
        
        System.out.println(s);  
    } 
}



/*
run:

23 May 2020 Greenwich Mean Time

*/

 




answered May 23 by avibootz
0 votes
import java.text.SimpleDateFormat;  
import java.util.Date;  

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();  
        SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");  
        String s = formatter.format(date);  
        
        System.out.println(s);  
    } 
}



/*
run:

Sat, 23 May 2020 07:44:45 GMT

*/

 




answered May 23 by avibootz
...