Java Date and Time conversion class SimpleDateFormat

Source: Internet
Author: User
Tags local time

and Time Pattern
DateResult
"YYYY. Mm.dd G ' at ' HH:mm:ss z ' 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM D, ' yy" Wed, Jul 4, ' 01
"H:mm a" 12:08 PM
"HH ' o ' clock ' A, zzzz" O ' clock PM, Pacific Daylight Time
"K:mm A, z" 0:08 PM, PDT
"Yyyyy. MMMMM.DD GGG hh:mm AAA " 02001.july.04 AD 12:08 PM
"EEE, D MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56-0700
"Yymmddhhmmssz" 010704120856-0700
"Yyyy-mm-dd ' T ' HH:mm:ss. Sssz " 2001-07-04t12:08:56.235-0700
"Yyyy-mm-dd ' T ' HH:mm:ss. Sssxxx " 2001-07-04t12:08:56.235-07:00
"Yyyy-' W ' Ww-u" 2001-w27-3


private static locale en_sg=new locale ("en", "SG");
public static final SimpleDateFormat sdf1 = new SimpleDateFormat ("Yyyy-mm-dd",
EN_SG);
public static final SimpleDateFormat sdf2 = new SimpleDateFormat ("dd MMM yyyy",
EN_SG);
public static final SimpleDateFormat sdf3 = new SimpleDateFormat ("Dd/mm/yyyy hh:mm",
EN_SG);
public static final SimpleDateFormat sdf4 = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. SSS ",
EN_SG);
public static final SimpleDateFormat sdf5 = new SimpleDateFormat ("EEE, dd MMM yyyy",
EN_SG);
public static final SimpleDateFormat Sdf6 = new SimpleDateFormat ("hh:mm AA",
EN_SG);
public static final SimpleDateFormat sdf7 = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss",
EN_SG);
public static final SimpleDateFormat Sdf8 = new SimpleDateFormat ("Eeeeeeeee, hh:mm AA",
EN_SG);
public static final SimpleDateFormat sdf9 = new SimpleDateFormat ("HH",
EN_SG);
public static final SimpleDateFormat SDF10 = new SimpleDateFormat ("hh:mm",
EN_SG);
public static final SimpleDateFormat sdf11= new SimpleDateFormat ("YyyyMMdd",
EN_SG);
public static final SimpleDateFormat sdf12 = new SimpleDateFormat ("AA", EN_SG);

public static final SimpleDateFormat sdf13 = new SimpleDateFormat ("hh:mm", EN_SG);
public static final SimpleDateFormat sdf14 = new SimpleDateFormat ("EE d MMM yyyy",
EN_SG);
public static final SimpleDateFormat Sdf15 = new SimpleDateFormat ("Yyyy-mm-dd hh:mm aaa",
EN_SG);

For UTC time transfer to SG local time use:
public static final SimpleDateFormat SDF4_UTC = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. SSS ",
Locale.english);
public static final SimpleDateFormat SDF7_UTC = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss",
Locale.english);
public static final SimpleDateFormat SDF13_UTC = new SimpleDateFormat ("hh:mm",
Locale.english);
public static int time_offset=0;
static{
Sdf4_utc.settimezone (Timezone.gettimezone ("Europe/london"));
Sdf7_utc.settimezone (Timezone.gettimezone ("Europe/london"));
Sdf13_utc.settimezone (Timezone.gettimezone ("Europe/london"));
TimeZone GMT = Timezone.gettimezone ("Europe/london");
Calendar gmtcal = Calendar.getinstance (GMT);
Time_offset = Gmtcal.get (Calendar.dst_offset);
LOG.D ("Gyy", "Time_offset" +time_offset);
}

String Datedisplay=constants.sdf5.format (Constants.sdf4.parse (medals.get (position). Getmedalupdatetime ()));


Java Date and Time conversion class SimpleDateFormat

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.