org.joda.time.format.DateTimeFormatter#withLocale ( )源码实例Demo

下面列出了org.joda.time.format.DateTimeFormatter#withLocale ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
源代码2 项目: sakai   文件: TimeUtil.java
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);
}
 
源代码3 项目: sakai   文件: TimeUtil.java
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);
}
 
源代码4 项目: cs-actions   文件: DateTimeService.java
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;
}
 
源代码5 项目: jasperreports   文件: DateTimeFunctions.java
/**
 * 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);	
	}
}
 
源代码6 项目: BootsFaces-OSP   文件: DateTimeConverter.java
private DateTimeFormatter getDateFormat(UIComponent uiComponent) {
	DateTimeFormatter format = DateTimeFormat.forPattern(getPattern(uiComponent));

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

	return format;
}
 
源代码7 项目: cs-actions   文件: DateTimeUtils.java
/**
 * 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);
}
 
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {
	return dateTimeFormatter.withLocale(Locale.US);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码13 项目: lams   文件: JodaTimeContextHolder.java
/**
 * 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);
}
 
/**
 * 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);
}