Skip to content

Instantly share code, notes, and snippets.

@chrishuan9
Created August 2, 2012 10:41
Show Gist options
  • Save chrishuan9/3236162 to your computer and use it in GitHub Desktop.
Save chrishuan9/3236162 to your computer and use it in GitHub Desktop.
DateFormat.java
import java.text.*;
import java.util.*;
public class DateFormat {
public static void main(String args[]) {
String s;
Format formatter;
Date date = new Date();
// 01/09/02
formatter = new SimpleDateFormat("MM/dd/yy");
s = formatter.format(date);
System.out.println(s);
// 01/09/02
formatter = new SimpleDateFormat("dd/MM/yy");
s = formatter.format(date);
System.out.println(s);
// 29-Jan-02
formatter = new SimpleDateFormat("dd-MMM-yy");
s = formatter.format(date);
System.out.println(s);
// 2002.01.29.08.36.33
formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
s = formatter.format(date);
System.out.println(s);
// Tue, 09 Jan 2002 22:14:02 -0500
formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
s = formatter.format(date);
System.out.println(s);
formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
s = formatter.format(date);
System.out.println(s);
}
}
Output
10/11/08
11/10/08
11-Oct-08
2008.10.11.12.08.24
Sat, 11 Oct 2008 12:08:24 +0530
Saturday, 11 October 2008 12:08:24 India Standard Time
@subhashrahangdale
Copy link

I need time zone like this

Sun Jan 24 2021 12:30:00 GMT+0530 (India Standard Time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment