public class Timeis { public static void main(String s[]) { long ts = 1022895271767L; SimpleDateFormat sdf = new SimpleDateFormat(" MMM d 'at' hh:mm a"); // CREATE DateFormatSymbols WITH ALL SYMBOLS FROM (DEFAULT) Locale DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); // OVERRIDE SOME symbols WHILE RETAINING OTHERS symbols.setAmPmStrings(new String[] { "am", "pm" }); sdf.setDateFormatSymbols(symbols); String st = sdf.format(ts); System.out.println("time is " + st); } }
public static String formatDateAsString(Date date) { // format date list grid cells SimpleDateFormat formatter = new SimpleDateFormat("MMM d, Y @ hh:mma"); DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); symbols.setAmPmStrings(new String[] { "am", "pm" }); formatter.setDateFormatSymbols(symbols); return formatter.format(date); }
import java.util.*; import java.text.*; public class Test { public static void main(String[] args) throws Exception { String text = "2013-05-23T09:18:07 p.m..380+0000"; String pattern = "yyyy-MM-dd'T'hh:mm:ss aa'.380+0000'"; SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols = (DateFormatSymbols) symbols.clone(); symbols.setAmPmStrings(new String[] { "a.m.", "p.m."}); format.setDateFormatSymbols(symbols); Date date = format.parse(text); System.out.println(date); } }
symbols.setAmPmStrings(new String[] { "am", "pm" }); formatter.setDateFormatSymbols(symbols);
/** * Sets am/pm strings. For example: "AM" and "PM". * @param newAmpms the new ampm strings. * @stable ICU 2.0 */ public void setAmPmStrings(String[] newAmpms) { dfs.setAmPmStrings(newAmpms); }
/** * Sets am/pm strings. For example: "AM" and "PM". * @param newAmpms the new ampm strings. * @stable ICU 2.0 */ public void setAmPmStrings(String[] newAmpms) { dfs.setAmPmStrings(newAmpms); }
public static DateFormatSymbols getDateFormatSymbols() { DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.getDefault()); dateFormatSymbols.setAmPmStrings(new String[]{AM_SYMBOL, PM_SYMBOL}); return dateFormatSymbols; }
DateFormatSymbols symbols = new DateFormatSymbols(); String[] modifiedAmPm = {"AM", "PM"}; symbols.setAmPmStrings(modifiedAmPm); Date date = new Date(); DateFormat formatter = new SimpleDateFormat("EEE, MMM dd, yyyy, h.mm a", symbols); String result = formatter.format(date);
DateFormatSymbols sym = new DateFormatSymbols(Locale.US); sym.setAmPmStrings(new String[] { "AM", "PM"}); SimpleDateFormat sdfBefore = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", sym); System.out.println("Debug: test6 = "+sdfBefore.format(System.currentTimeMillis())); System.out.println("Debug: test9 = "+sdfBefore.parse("05/26/2014 06:57:09 AM"));
public static void main(String[] args) throws ParseException { DateFormatSymbols instance = DateFormatSymbols.getInstance(); instance.setAmPmStrings(new String[]{"a","p"}); SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy hh:mma",instance); Date parsedDate = format.parse("12/31/2008 3:28p"); System.out.println(parsedDate); }
@Override public void setAmPmStrings(String[] newAmpms) { if (fIcuDfs == null) { super.setAmPmStrings(newAmpms); return; } fIcuDfs.setAmPmStrings(newAmpms); }
SimpleDateFormat sdf = (SimpleDateFormat)sdf.getDateTimeInstance(DateTime.SHORT,DateTime.SHORT, locale); if (formatString != null) { sdf = new SimpleDateFormat(formatString); } if (am!= null && pm != null) { DateFormatSymbols symbols = sdf.getDateFormatSymbols(); symbols.setAmPmStrings(new String[]{am, pm}); sdf.setDateFormatSymbols(symbols); }
public static SimpleDateFormat targetFormat = new SimpleDateFormat(); public static SimpleDateFormat originalFormat = new SimpleDateFormat(); public static String formattedDate = ""; public static String getFormattedDate(String targetPattern, String existingPattern, String existingValue) { formattedDate = existingValue; targetFormat.applyPattern(targetPattern); DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); symbols.setAmPmStrings(new String[] { "AM", "PM" }); targetFormat.setDateFormatSymbols(symbols); originalFormat.applyPattern(existingPattern); try { formattedDate = targetFormat.format(originalFormat .parse(existingValue)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return formattedDate; }
public DateParser(final Locale locale) { this.locale = locale; this.dateFormatSymbols = DateFormatSymbols.getInstance(locale); if (Locale.CANADA.getCountry().equals(locale.getCountry()) || Locale.US.getCountry().equals(locale.getCountry())) { this.universalFormats = new SimpleDateFormat[]{ new SimpleDateFormat("M d yyyy h.mm.ss aa", Locale.US), new SimpleDateFormat("M d yyyy H.mm.ss", Locale.US), }; } else if (Locale.JAPAN.getLanguage().equals(locale.getLanguage())) { this.universalFormats = new SimpleDateFormat[] { new SimpleDateFormat("yyyy M d h.mm.ss aa", Locale.US), new SimpleDateFormat("yyyy M d H.mm.ss", Locale.US), }; } else { this.universalFormats = new SimpleDateFormat[] { new SimpleDateFormat("d M yyyy h.mm.ss aa", Locale.US), new SimpleDateFormat("d M yyyy H.mm.ss", Locale.US), new SimpleDateFormat("d. M yyyy h.mm.ss aa", Locale.US), new SimpleDateFormat("d. M yyyy H.mm.ss", Locale.US), }; } if (Locale.GERMAN.getLanguage().equals(locale.getLanguage())) { this.dateFormatSymbols.setAmPmStrings(new String[]{"vorm.", "nachm."}); } if ("nl".equals(locale.getLanguage())) { this.dateFormatSymbols.setAmPmStrings(new String[]{"a.m.", "p.m."}); } }
String text = "2013-05-23T09:18:07 p.m..380+0000"; String pattern = "yyyy-MM-dd'T'hh:mm:ss aa'.'SSSZ"; SimpleDateFormat format = new SimpleDateFormat(pattern); DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols = (DateFormatSymbols) symbols.clone(); symbols.setAmPmStrings(new String[] { "a.m.", "p.m."}); format.setDateFormatSymbols(symbols); Date date = format.parse(text); System.out.println(date);
/** * Allows the AM/PM text to be set. * * @param am AM text * @param pm PM text */ public void setAmPmText(String am, String pm) { for (SimpleDateFormat format : m_formats) { DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols.setAmPmStrings(new String[] { am, pm }); format.setDateFormatSymbols(symbols); } }
/** * Allows the AM/PM text to be set. * * @param am AM text * @param pm PM text */ public void setAmPmText(String am, String pm) { for (SimpleDateFormat format : m_formats) { DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols.setAmPmStrings(new String[] { am, pm }); format.setDateFormatSymbols(symbols); } }
void addDateP(String _pattern, boolean _heuristic, boolean _yearOverride) { if (_heuristic) { if (_pattern.indexOf("a") < 0 && _pattern.indexOf("H") > 0) { String chg = _pattern.replaceAll("H", "h") + " a"; addDateP(chg, false, false); addTogglePattern(chg); } } SimpleDateFormat sdf = new SimpleDateFormat(_pattern, locale); ((GregorianCalendar) sdf.getCalendar()).setGregorianChange(new java.util.Date(Long.MIN_VALUE)); sdf.setLenient(false); if ("true".equalsIgnoreCase(getRS())) { DateFormatSymbols df = new DateFormatSymbols(); df.setAmPmStrings(new String[] { "AM", "PM" }); sdf.setDateFormatSymbols(df); } dateFormats.put(sdf, _yearOverride); if (_heuristic) { addTogglePattern(_pattern); if (_pattern.endsWith(" a") && _pattern.indexOf("h") > 0) { String chg = _pattern.substring(0, _pattern.length() - 2).trim().replaceAll("h", "H"); addDateP(chg, false, false); addTogglePattern(chg); } } }
SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.FRI", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.SAT", locale) }); symbols.setAmPmStrings(new String[] { SakaiLocaleServiceProviderUtil.getString("AmPmStrings.AM", locale), SakaiLocaleServiceProviderUtil.getString("AmPmStrings.PM", locale) });