本文整理了Java中org.joda.time.format.DateTimeFormatter.withZoneUTC()
方法的一些代码示例,展示了DateTimeFormatter.withZoneUTC()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.withZoneUTC()
方法的具体详情如下:
包路径:org.joda.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:withZoneUTC
[英]Returns a new formatter that will use the UTC zone in preference to the zone of the printed object, or default zone on a parse.
When printing, UTC will be used in preference to the zone from the datetime that would otherwise be used.
When parsing, UTC will be set on the parsed datetime.
If both an override chronology and an override zone are set, the override zone will take precedence over the zone in the chronology.
[中]返回一个新的格式化程序,该格式化程序将优先使用UTC区域而不是打印对象的区域,或解析时的默认区域。
打印时,UTC将优先于使用日期时间的区域。
解析时,将在解析的日期时间上设置UTC。
如果同时设置了替代年表和替代分区,则替代分区将优先于年表中的分区。
代码示例来源:origin: Graylog2/graylog2-server
private String dateFormat(final DateTime x) {
return x.toString(DateTimeFormat.forPattern(Tools.ES_DATE_FORMAT_NO_MS).withZoneUTC());
}
}
代码示例来源:origin: apache/flume
public SyslogParser() {
timeParser = DateTimeFormat.forPattern(timePat).withZoneUTC();
timestampCache = CacheBuilder.newBuilder().maximumSize(TS_CACHE_MAX).build(
new CacheLoader<String, Long>() {
@Override
public Long load(String key) throws Exception {
return timeParser.parseMillis(key);
}
});
}
代码示例来源:origin: joda-time/joda-time
private static DateTimeFormatter localDateParser() {
if (ldp == null) {
return dateElementParser().withZoneUTC();
}
return ldp;
}
代码示例来源:origin: JodaOrg/joda-time
private static DateTimeFormatter localDateParser() {
if (ldp == null) {
return dateElementParser().withZoneUTC();
}
return ldp;
}
代码示例来源:origin: prestodb/presto
public static boolean timestampHasTimeZone(String value)
{
try {
try {
TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseMillis(value);
return true;
}
catch (RuntimeException e) {
// `.withZoneUTC()` makes `timestampHasTimeZone` return value independent of JVM zone
TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withZoneUTC().parseMillis(value);
return false;
}
}
catch (RuntimeException e) {
throw new IllegalArgumentException(format("Invalid timestamp '%s'", value));
}
}
代码示例来源:origin: prestodb/presto
public CustomDateTimeJsonFieldDecoder(DecoderColumnHandle columnHandle)
{
this.columnHandle = requireNonNull(columnHandle, "columnHandle is null");
if (!SUPPORTED_TYPES.contains(columnHandle.getType())) {
throwUnsupportedColumnType(columnHandle);
}
checkArgument(columnHandle.getFormatHint() != null, "format hint not defined for column '%s'", columnHandle.getName());
try {
formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC();
}
catch (IllegalArgumentException e) {
throw new PrestoException(
GENERIC_USER_ERROR,
format("invalid joda pattern '%s' passed as format hint for column '%s'", columnHandle.getFormatHint(), columnHandle.getName()));
}
}
代码示例来源:origin: prestodb/presto
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.date().withZoneUTC();
filter.add(dateTimeFormatter.print(TimeUnit.DAYS.toMillis((long) value)));
代码示例来源:origin: apache/incubator-pinot
entries.add(new Object[]{"5:MINUTES:EPOCH", 1498892400000L, Long.class, 4996308L});
entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd", 1498892400000L, String.class, DateTimeFormat
.forPattern("yyyyMMdd").withZoneUTC().print(1498892400000L)});
entries.add(
new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd tz(America/New_York)", 1498892400000L, String.class, DateTimeFormat
1498892400000L)});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH", 1498892400000L, String.class, DateTimeFormat
.forPattern("yyyyMMdd HH").withZoneUTC().print(1498892400000L)});
entries.add(
new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH tz(IST)", 1498892400000L, String.class, DateTimeFormat
1498892400000L)});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z", 1498892400000L, String.class, DateTimeFormat
.forPattern("yyyyMMdd HH Z").withZoneUTC().print(1498892400000L)});
entries.add(
new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z tz(GMT+0500)", 1498892400000L, String.class, DateTimeFormat
entries.add(
new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h:mm:ss a", 1498892400000L, String.class, DateTimeFormat
.forPattern("M/d/yyyy h:mm:ss a").withZoneUTC().print(1498892400000L)});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h a", 1502066750000L, String.class, DateTimeFormat
.forPattern("M/d/yyyy h a").withZoneUTC().print(1502066750000L)});
return entries.toArray(new Object[entries.size()][]);
代码示例来源:origin: apache/incubator-pinot
@DataProvider(name = "testFromFormatToMillisDataProvider")
public Object[][] provideTestFromFormatToMillisData() {
List<Object[]> entries = new ArrayList<>();
entries.add(new Object[]{"1:HOURS:EPOCH", 416359L, 1498892400000L});
entries.add(new Object[]{"1:MILLISECONDS:EPOCH", 1498892400000L, 1498892400000L});
entries.add(new Object[]{"1:HOURS:EPOCH", 0L, 0L});
entries.add(new Object[]{"5:MINUTES:EPOCH", 4996308L, 1498892400000L});
entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd", "20170701", DateTimeFormat.forPattern("yyyyMMdd")
.withZoneUTC().parseMillis("20170701")});
entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd tz(America/Chicago)", "20170701", DateTimeFormat
.forPattern("yyyyMMdd").withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Chicago"))).parseMillis(
"20170701")});
entries.add(
new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH", "20170701 00", DateTimeFormat.forPattern("yyyyMMdd HH")
.withZoneUTC().parseMillis("20170701 00")});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH tz(GMT+0600)", "20170701 00", DateTimeFormat
.forPattern("yyyyMMdd HH").withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0600"))).parseMillis(
"20170701 00")});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z", "20170701 00 -07:00", 1498892400000L});
entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h:mm:ss a", "8/7/2017 12:45:50 AM", 1502066750000L});
return entries.toArray(new Object[entries.size()][]);
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of running a query with timestamp query parameters. */
public void runQueryWithTimestampParameters() throws InterruptedException {
// [START bigquery_query_params_timestamps]
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
DateTime timestamp = new DateTime(2016, 12, 7, 8, 0, 0, DateTimeZone.UTC);
String query = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);";
// Note: Standard SQL is required to use query parameters.
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(query)
.addNamedParameter(
"ts_value",
QueryParameterValue.timestamp(
// Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
timestamp.getMillis() * 1000))
.build();
// Print the results.
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
System.out.printf(
"%s\n",
formatter.print(
new DateTime(
// Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC,
// but org.joda.time.DateTime constructor accepts times in milliseconds.
row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC)));
System.out.printf("\n");
}
// [END bigquery_query_params_timestamps]
}
代码示例来源:origin: joda-time/joda-time
private static DateTimeFormatter localTimeParser() {
if (ltp == null) {
return new DateTimeFormatterBuilder()
.appendOptional(literalTElement().getParser())
.append(timeElementParser())
.toFormatter().withZoneUTC();
}
return ltp;
}
代码示例来源:origin: Graylog2/graylog2-server
/**
* Accepts our ElasticSearch time formats without milliseconds.
*
* @return A DateTimeFormatter suitable to parse an ES_DATE_FORMAT formatted string to a
* DateTime Object even if it contains no milliseconds.
*/
public static DateTimeFormatter timeFormatterWithOptionalMilliseconds() {
// This is the .SSS part
DateTimeParser ms = new DateTimeFormatterBuilder()
.appendLiteral(".")
.appendFractionOfSecond(1, 3)
.toParser();
return new DateTimeFormatterBuilder()
.append(DateTimeFormat.forPattern(ES_DATE_FORMAT_NO_MS).withZoneUTC())
.appendOptional(ms)
.toFormatter();
}
代码示例来源:origin: JodaOrg/joda-time
private static DateTimeFormatter localTimeParser() {
if (ltp == null) {
return new DateTimeFormatterBuilder()
.appendOptional(literalTElement().getParser())
.append(timeElementParser())
.toFormatter().withZoneUTC();
}
return ltp;
}
代码示例来源:origin: joda-time/joda-time
private static DateTimeFormatter localDateOptionalTimeParser() {
if (ldotp == null) {
DateTimeParser time = new DateTimeFormatterBuilder()
.appendLiteral('T')
.append(timeElementParser())
.toParser();
return new DateTimeFormatterBuilder()
.append(dateElementParser())
.appendOptional(time)
.toFormatter().withZoneUTC();
}
return ldotp;
}
代码示例来源:origin: JodaOrg/joda-time
private static DateTimeFormatter localDateOptionalTimeParser() {
if (ldotp == null) {
DateTimeParser time = new DateTimeFormatterBuilder()
.appendLiteral('T')
.append(timeElementParser())
.toParser();
return new DateTimeFormatterBuilder()
.append(dateElementParser())
.appendOptional(time)
.toFormatter().withZoneUTC();
}
return ldotp;
}
代码示例来源:origin: OfficeDev/ews-java-api
private static DateTimeFormatter[] createDateTimeFormats() {
return new DateTimeFormatter[] {
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-ddZ").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC()
};
}
代码示例来源:origin: OfficeDev/ews-java-api
private static DateTimeFormatter[] createDateFormats() {
return new DateTimeFormatter[] {
DateTimeFormat.forPattern("yyyy-MM-ddZ").withZoneUTC(),
DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC()
};
}
代码示例来源:origin: prestodb/presto
private static final String DATE_STRING = DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC().print(DATE_MILLIS_UTC);
private static final Date SQL_DATE = new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), DATE_MILLIS_UTC));
代码示例来源:origin: org.elasticsearch/elasticsearch
private static DateTimeFormatter localDateParser() {
if (ldp == null) {
return dateElementParser().withZoneUTC();
}
return ldp;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static DateTimeFormatter localTimeParser() {
if (ltp == null) {
return new DateTimeFormatterBuilder()
.appendOptional(literalTElement().getParser())
.append(timeElementParser())
.toFormatter().withZoneUTC();
}
return ltp;
}
内容来源于网络,如有侵权,请联系作者删除!