Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to change date format in a String with Java

1 Answer

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

public class MyClass {
    public static void main(String args[]) {
        Date date = new Date();
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        SimpleDateFormat newFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        
        String strDate = format.format(date);
        System.out.println("Date: " + strDate);
        
        String newDate = newFormat.format(date);
        System.out.println("New date: " + newDate);
    }
}
  
  
  
  
/*
run:
  
Date: 2023/11/27 13:55:33
New date: 27-11-2023 13:55:33
  
*/

 



answered Nov 27, 2023 by avibootz

Related questions

1 answer 189 views
1 answer 149 views
1 answer 124 views
1 answer 118 views
1 answer 97 views
...