Java Code Examples for java.text.SimpleDateFormat#toLocalizedPattern()

The following examples show how to use java.text.SimpleDateFormat#toLocalizedPattern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtil.java    From Klyph with MIT License 6 votes vote down vote up
private static String getFormattedFullDate(Date date)
{
	SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
	String pattern = dateFormat.toLocalizedPattern();

	pattern = pattern.replace("E", "");
	pattern = pattern.replace(",", "");
	pattern = pattern.replace("  ", " ");
	pattern = pattern.trim();
	
	dateFormat.applyLocalizedPattern(pattern);

	return dateFormat.format(date);
}
 
Example 2
Source File: DateUtilsTest.java    From jakduk-api with MIT License 6 votes vote down vote up
@Test
public void dateFormatTest() throws ParseException {
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, Locale.ENGLISH);
    SimpleDateFormat sf = (SimpleDateFormat) df;
    String p1 = sf.toPattern();
    String p2 = sf.toLocalizedPattern();

    Assert.assertTrue("MMM d, yyyy h:mm a".equals(p1));
    Assert.assertTrue("MMM d, yyyy h:mm a".equals(p2));

    DateFormat koreaDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.KOREA);

    Assert.assertTrue("yy. M. d a h:mm".equals(((SimpleDateFormat)koreaDateFormat).toPattern()));

    LocalDateTime dateTime1 = LocalDateTime.parse("Thu, 5 Jun 2014 05:10:40 GMT", DateTimeFormatter.RFC_1123_DATE_TIME);

    Assert.assertTrue("2014-06-05T05:10:40".equals(dateTime1.toString()));

    LocalDate localDate = LocalDate.of(2017, 8, 7);
    DateTimeFormatter df02 = DateTimeFormatter.ISO_DATE;
    Assert.assertTrue("2017-08-07".equals(localDate.format(df02)));
}
 
Example 3
Source File: UtcDates.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
static String getTextInputHint(Resources res, SimpleDateFormat format) {
  String formatHint = format.toLocalizedPattern();
  String yearChar = res.getString(R.string.mtrl_picker_text_input_year_abbr);
  String monthChar = res.getString(R.string.mtrl_picker_text_input_month_abbr);
  String dayChar = res.getString(R.string.mtrl_picker_text_input_day_abbr);

  return formatHint.replaceAll("d", dayChar).replaceAll("M", monthChar).replaceAll("y", yearChar);
}
 
Example 4
Source File: DateUtil.java    From Klyph with MIT License 5 votes vote down vote up
private static SimpleDateFormat getDateFormat()
{
	SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
	String pattern = dateFormat.toLocalizedPattern();

	pattern = pattern.replace("y", "");
	pattern = pattern.replace("E", "");
	pattern = pattern.replace(",", "");
	pattern = pattern.replace("  ", " ");
	pattern = pattern.trim();

	dateFormat.applyLocalizedPattern(pattern);

	return dateFormat;
}
 
Example 5
Source File: DatePickerDialog.java    From material with Apache License 2.0 4 votes vote down vote up
private boolean isMonthFirst(){
    SimpleDateFormat format = (SimpleDateFormat)SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
    String pattern = format.toLocalizedPattern();

    return pattern.indexOf("M") < pattern.indexOf("d");
}
 
Example 6
Source File: RunHistoryPanel.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private static String getShortLocaleDatePattern() {
	DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
	SimpleDateFormat sf = (SimpleDateFormat) df;
	System.out.println("*********** " + sf.toLocalizedPattern());
	return sf.toLocalizedPattern();
}