Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Obtain date in format yyyy mm dd hhmmss in Java

Obtain date in format yyyy mm dd hhmmss - Java:


import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class DateTime {
   /**
   * This method Obtain date in format yyyy mm dd hhmmss with javadoc
   * @param args the command line arguments
   */   
   public static void main(String[] args) {
      //Create a LocalDateTime object
      LocalDateTime dateTime = LocalDateTime.now();
      //Create a DateTimeFormatter object
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
      //Format the date time using formatter object
      String formatDateTime = dateTime.format(formatter);
      //Print the formatted date time
      System.out.println("Current Date Time: " + formatDateTime);
   }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)