Java 类org.apache.logging.log4j.core.util.datetime.FastDateFormat 实例源码

项目:log4j2-logstash-layout    文件:LogstashLayout.java   
private LogstashLayout(Builder builder) {
    super(builder.config, StandardCharsets.UTF_8, null, null);
    String template = readTemplate(builder);
    FastDateFormat timestampFormat = readDateFormat(builder);
    ObjectMapper objectMapper = new ObjectMapper();
    StrSubstitutor substitutor = builder.config.getStrSubstitutor();
    TemplateResolverContext resolverContext = TemplateResolverContext
            .newBuilder()
            .setObjectMapper(objectMapper)
            .setTimestampFormat(timestampFormat)
            .setLocationInfoEnabled(builder.locationInfoEnabled)
            .setStackTraceEnabled(builder.stackTraceEnabled)
            .setMdcKeyPattern(builder.mdcKeyPattern)
            .setNdcPattern(builder.ndcPattern)
            .build();
    this.renderer = TemplateRenderer
            .newBuilder()
            .setSubstitutor(substitutor)
            .setResolverContext(resolverContext)
            .setPrettyPrintEnabled(builder.prettyPrintEnabled)
            .setTemplate(template)
            .setResolvers(RESOLVERS)
            .build();
}
项目:motu    文件:NetCdfReader.java   
/**
 * Returns a GMT string representation (yyyy-MM-dd HH:mm:ss) without time if 0 ((yyyy-MM-dd) from a date
 * value and an udunits string.
 * 
 * @param date Date object to convert
 * 
 * @return a string representation of the date
 */
public static String getDateAsGMTNoZeroTimeString(Date date) {
    if (date == null) {
        return "";
    }
    GregorianCalendar calendar = new GregorianCalendar(GMT_TIMEZONE);
    calendar.setTime(date);

    int h = calendar.get(Calendar.HOUR_OF_DAY);
    int m = calendar.get(Calendar.MINUTE);
    int s = calendar.get(Calendar.SECOND);

    String format = DATETIME_FORMAT;
    if ((h == 0) && (m == 0) && (s == 0)) {
        format = DATE_FORMAT;
    }
    return FastDateFormat.getInstance(format, GMT_TIMEZONE).format(date);
}
项目:log4j2-logstash-layout    文件:TimestampResolver.java   
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    long timestampMillis = logEvent.getTimeMillis();
    FastDateFormat timestampFormat = context.getTimestampFormat();
    String timestamp = timestampFormat.format(timestampMillis);
    return new TextNode(timestamp);
}
项目:log4j2-elasticsearch    文件:RollingIndexNameFormatter.java   
protected RollingIndexNameFormatter(String indexName, String pattern, long initTimeInMillis, TimeZone timeZone) {
    this.indexName = indexName;
    this.fastDateFormat = FastDateFormat.getInstance(pattern, timeZone);
    this.patternProcessor = createPatternProcessor(pattern);
    this.currentName = doFormat(indexName, initTimeInMillis);

    long previousTime = this.patternProcessor.getNextTime(initTimeInMillis, -1, false);
    this.patternProcessor.setPrevFileTime(previousTime);
    this.nextRolloverTime = this.patternProcessor.getNextTime(initTimeInMillis, 0, false);
    this.currentFileTime = this.nextRolloverTime;
}
项目:log4j2-logstash-layout    文件:LogstashLayout.java   
private static FastDateFormat readDateFormat(Builder builder) {
    TimeZone timeZone = TimeZone.getTimeZone(builder.timeZoneId);
    return FastDateFormat.getInstance(builder.dateTimeFormatPattern, timeZone);
}
项目:log4j2-logstash-layout    文件:TemplateResolverContext.java   
public FastDateFormat getTimestampFormat() {
    return timestampFormat;
}
项目:log4j2-logstash-layout    文件:TemplateResolverContext.java   
public FastDateFormat getTimestampFormat() {
    return timestampFormat;
}
项目:log4j2-logstash-layout    文件:TemplateResolverContext.java   
public Builder setTimestampFormat(FastDateFormat timestampFormat) {
    this.timestampFormat = timestampFormat;
    return this;
}
项目:motu    文件:NetCdfReader.java   
/**
 * Returns a GMT string representation (yyyy-MM-dd HH:mm:ss) from a date value and an udunits string.
 * 
 * @param unitsString udunits string
 * @param value value of the date
 * 
 * @return a string representation of the date
 * 
 * @throws MotuException the motu exception
 */
public static String getDateAsGMTString(double value, String unitsString) throws MotuException {

    Date date = NetCdfReader.getDate(value, unitsString);

    return FastDateFormat.getInstance(DATETIME_FORMAT, GMT_TIMEZONE).format(date);
    // return GMTDateFormat.TO_STRING_DEFAULT.format(date);
    // return DateFormat.getInstance().format(date);
}