Java Date Formatting

Java SimpleDateFormat Class Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

Add Comment

    • /**
      *
      */
      package com.dateformat;

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

      /**
      * @author Nagaraju
      *
      */
      public class DateFormat {

      /**
      * @param args
      */
      public static void main(String[] args) {
      // Auto-generated method stub
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“EEE MMM dd HH:mm:ss zzz yyyy”, Locale.US);
      simpleDateFormat.setTimeZone(TimeZone.getTimeZone(“GMT”));
      String todayGMT = simpleDateFormat.format(new Date());
      System.out.println(todayGMT);

      Date today = new Date();
      System.out.println(today.toString());

      }

      }

Sponsors

Facebook Fans

Online Shopping – Flipkart