Here you can find the source of getTimeWithFormat(String stringDate, String dateFormat, DateTimeZone timeZone, Locale locale)
Parameter | Description |
---|---|
time | a parameter |
dateFormat | a parameter |
Parameter | Description |
---|---|
ASKFastCheckedException | an exception |
public static DateTime getTimeWithFormat(String stringDate, String dateFormat, DateTimeZone timeZone, Locale locale)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; public class Main { private static final String serverTimezone = "Europe/Amsterdam"; /**//from w w w . j av a 2s. c om * e.g. 10:45:42 in HH:mm:ss or January 02, 2010 in "MMMM d, yyyy" etc to * its DateTime equivalent format * * @param time * @param dateFormat * @return * @throws ASKFastCheckedException */ public static DateTime getTimeWithFormat(String stringDate, String dateFormat, DateTimeZone timeZone, Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; timeZone = timeZone != null ? timeZone : getServerDateTimeZone(); try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, locale); simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone.getID())); Date parsedDate = simpleDateFormat.parse(stringDate); return new DateTime(parsedDate, timeZone); } catch (ParseException e) { return null; } } public static DateTimeZone getServerDateTimeZone() { return DateTimeZone.forID(serverTimezone); } }