Java Code Examples for org.joda.time.format.DateTimeFormatter#withLocale()

The following examples show how to use org.joda.time.format.DateTimeFormatter#withLocale() . 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: DateUtils.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
private static DateTimeFormatter getDateTimeFormatter(String outputPattern, String language)
{
    DateTimeFormatter formatter = DateTimeFormat.forPattern(outputPattern);
    if ( language.equals(US) )
    {
        formatter = formatter.withLocale(Locale.US);
    }
    else if ( language.equals(DE) )
    {
        formatter = formatter.withLocale(Locale.GERMAN);
    }
    else if ( language.equals(JA) )
    {
        formatter = formatter.withLocale(Locale.JAPANESE);
    }
    return formatter;
}
 
Example 2
Source File: TimeUtil.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getIsoDateWithLocalTime(Date dateToConvert) {
    if (dateToConvert == null) {
        return null;
    }
    DateTime dt = new DateTime(dateToConvert);
    DateTimeFormatter fmt = ISODateTimeFormat.yearMonthDay();
    DateTimeFormatter localFmt = fmt.withLocale(new ResourceLoader().getLocale());
    DateTimeFormatter fmtTime = DateTimeFormat.shortTime();
    DateTimeFormatter localFmtTime = fmtTime.withLocale(new ResourceLoader().getLocale());

    // If the client browser is in a different timezone than server, need to modify date
    if (m_client_timezone !=null && m_server_timezone!=null && !m_client_timezone.hasSameRules(m_server_timezone)) {
      DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(m_client_timezone);
      localFmt = localFmt.withZone(dateTimeZone);
      localFmtTime = localFmtTime.withZone(dateTimeZone);
    }
    return dt.toString(localFmt) + " " + dt.toString(localFmtTime);
}
 
Example 3
Source File: TimeUtil.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getIsoDateWithLocalTime(Date dateToConvert) {
    if (dateToConvert == null) {
        return null;
    }
    DateTime dt = new DateTime(dateToConvert);
    DateTimeFormatter fmt = ISODateTimeFormat.yearMonthDay();
    DateTimeFormatter localFmt = fmt.withLocale(new ResourceLoader().getLocale());
    DateTimeFormatter fmtTime = DateTimeFormat.shortTime();
    DateTimeFormatter localFmtTime = fmtTime.withLocale(new ResourceLoader().getLocale());

    // If the client browser is in a different timezone than server, need to modify date
    if (m_client_timezone !=null && m_server_timezone!=null && !m_client_timezone.hasSameRules(m_server_timezone)) {
      DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(m_client_timezone);
      localFmt = localFmt.withZone(dateTimeZone);
      localFmtTime = localFmtTime.withZone(dateTimeZone);
    }
    return dt.toString(localFmt) + " " + dt.toString(localFmtTime);
}
 
Example 4
Source File: DateTimeService.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
private static DateTimeFormatter getDateTimeFormatter(final String localeLang, final String localeCountry, final String timezone, final String dateFormat) {
    DateTimeFormatter formatter;
    if (StringUtilities.isNoneBlank(dateFormat)) {
        formatter = DateTimeFormat.forPattern(dateFormat);
    } else {
        formatter = DateTimeFormat.longDateTime();
    }

    if (isNotBlank(timezone)) {
        formatter = formatter.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timezone)));
    }

    if (isNotBlank(localeLang)) {
        formatter = formatter.withLocale(DateTimeUtils.getLocaleByCountry(localeLang, localeCountry));
    }
    return formatter;
}
 
Example 5
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Format the specified date object using the chosen format pattern.
 */
@Function("DATEFORMAT")
@FunctionParameters({
	@FunctionParameter("dateObj"),
	@FunctionParameter("formatPattern")})
public String DATEFORMAT(Date dateObj, String formatPattern){
	if(dateObj==null){
		return null;
	}
	else{
		DateTimeFormatter formatter = DateTimeFormat.forPattern(formatPattern);
		formatter = formatter.withLocale(getReportLocale());
		return new DateTime(dateObj,DateTimeZone.forTimeZone(getReportTimeZone())).toString(formatter);	
	}
}
 
Example 6
Source File: DateTimeConverter.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private DateTimeFormatter getDateFormat(UIComponent uiComponent) {
	DateTimeFormatter format = DateTimeFormat.forPattern(getPattern(uiComponent));

	format = format.withLocale(SessionPreferences.getCurrentLocale());
	format = format.withZone(getTimeZone());

	return format;
}
 
Example 7
Source File: DateTimeUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a DateTimeFormatter using a custom pattern with the default locale or a new one
 * according to what language and country are provided as params.
 *
 * @param format  the pattern
 * @param lang    the language
 * @param country the country
 * @return the DateTimeFormatter generated
 */
public static DateTimeFormatter getDateFormatter(String format, String lang, String country) {
    if (StringUtils.isNotBlank(format)) {
        DateTimeFormatter dateFormat = DateTimeFormat.forPattern(format);
        if (StringUtils.isNotBlank(lang)) {
            return dateFormat.withLocale(DateTimeUtils.getLocaleByCountry(lang, country));
        }
        return dateFormat;
    }
    return formatWithDefault(lang, country);
}
 
Example 8
Source File: DateTimeFormatterFactoryTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
Example 9
Source File: DateTimeFormatterFactoryTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
Example 10
Source File: DateTimeFormatterFactoryTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
Example 11
Source File: JodaTimeContextHolder.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
 * @param formatter the base formatter that establishes default formatting rules
 * (generally user independent)
 * @param locale the current user locale (may be {@code null} if not known)
 * @return the user-specific DateTimeFormatter
 */
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) {
	DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
	JodaTimeContext context = getJodaTimeContext();
	return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}
 
Example 12
Source File: JodaTimeContextHolder.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
 * @param formatter the base formatter that establishes default formatting rules
 * (generally user independent)
 * @param locale the current user locale (may be {@code null} if not known)
 * @return the user-specific DateTimeFormatter
 */
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) {
	DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
	JodaTimeContext context = getJodaTimeContext();
	return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}
 
Example 13
Source File: JodaTimeContextHolder.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
 * @param formatter the base formatter that establishes default formatting rules
 * (generally user independent)
 * @param locale the current user locale (may be {@code null} if not known)
 * @return the user-specific DateTimeFormatter
 */
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
	DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
	JodaTimeContext context = getJodaTimeContext();
	return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}
 
Example 14
Source File: JodaTimeContextHolder.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
 * @param formatter the base formatter that establishes default formatting rules
 * (generally user independent)
 * @param locale the current user locale (may be {@code null} if not known)
 * @return the user-specific DateTimeFormatter
 */
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
	DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
	JodaTimeContext context = getJodaTimeContext();
	return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}