Example usage for org.joda.time DateTimeZone UTC

List of usage examples for org.joda.time DateTimeZone UTC

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone UTC.

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.google.soxlib.Utility.java

License:Apache License

/**
 * Get the time now in a string format suitable for use in SOX timestamp
 * fields.// w w w.java  2s  .  c  om
 *
 * @return UTC timestamp to the nearest millisecond as a string.
 */
public static final String getTimestampNow() {
    DateTime now = new DateTime(DateTimeZone.UTC);
    return now.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC));
}

From source file:com.google.soxlib.Utility.java

License:Apache License

/**
 * Convert from "unix time" (utc milliseconds since 1970) into a string format
 * for use in SOX timestamp fields./*from  w w w .j a  v a2 s . c o m*/
 *
 * @param timestampMsUtc utc time in milliseconds since Jan 1, 1970 (aka unix
 *        time).
 * @return UTC timestamp to the nearest millisecond as a string.
 */
public static final String getTimestampFromUnixTime(long timestampMsUtc) {
    DateTime dt = new DateTime(timestampMsUtc, DateTimeZone.UTC);
    return dt.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC));
}

From source file:com.google.soxlib.Utility.java

License:Apache License

/**
 * Verify that the string provided is a valid RFC 3339 timestamp string and
 * converts the string into the UTC timezone for use by the SOX library.
 *
 * @param timestamp string to be verified.
 * @return timestamp converted to UTC in the SOX format.
 * @throws IllegalArgumentException if the string cannot be converted to UTC.
 *///from  www. ja va2  s  .c o m
public static final String verifyTimestamp(String timestamp) throws IllegalArgumentException {
    Matcher m = Utility.SIMPLE_TIMESTAMP_CHECK.matcher(timestamp);
    if (!m.find()) {
        throw new IllegalArgumentException("timestamp not valid");
    }
    // convert entered value to the ISO standard and make that
    // the official value
    DateTime dt;
    try {
        dt = new DateTime(timestamp);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("timestamp not valid");
    }

    return dt.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC));
}

From source file:com.google.walkaround.wave.server.googleimport.DaysSinceEpoch.java

License:Open Source License

public static long fromLocalDate(LocalDate d) {
    return fromDateMidnight(d.toDateMidnight(DateTimeZone.UTC));
}

From source file:com.google.walkaround.wave.server.googleimport.DaysSinceEpoch.java

License:Open Source License

public static DateMidnight toDateMidnightUTC(long daysSinceEpoch) {
    return new DateMidnight(daysSinceEpoch * MILLIS_PER_DAY, DateTimeZone.UTC);
}

From source file:com.greenowl.callisto.web.rest.dto.ParkingActivityDTO.java

public ParkingActivityDTO(ParkingActivity activity, User user) {
    this.id = activity.getId();
    this.lotId = activity.getId();
    this.userEmail = user.getLogin();
    this.userPhoneNumber = user.getMobileNumber();
    this.userPlateNumber = user.getLicensePlate();
    this.type = activity.getType();
    this.saleId = activity.getSaleId();
    this.deviceInfo = activity.getDeviceInfo();
    if (activity.getEntryDatetime() != null) {
        this.entryDateTime = activity.getEntryDatetime().withZone(DateTimeZone.UTC).getMillis();
    }/*from w  ww . j a  v a  2  s  .  co m*/
    if (activity.getExitDatetime() != null) {
        this.exitDateTime = activity.getExitDatetime().withZone(DateTimeZone.UTC).getMillis();
    }
    this.parkingStatus = activity.getParkingStatus();
    this.exceptionFlag = activity.getExceptionFlag();
    if (activity.getCreatedDate() != null) {
        this.createdDate = activity.getCreatedDate().withZone(DateTimeZone.UTC).getMillis();
    }
}

From source file:com.groupon.lex.metrics.history.v0.xdr.FromXdr.java

public static DateTime timestamp(timestamp_msec ts) {
    return new DateTime(ts.value, DateTimeZone.UTC);
}

From source file:com.groupon.lex.metrics.history.xdr.support.FileSupport0.java

@Override
public void create_file(TSDataVersionDispatch.Releaseable<FileChannel> fd,
        Collection<? extends TimeSeriesCollection> tsdata, boolean compress) throws IOException {
    try {//  ww w  .java2 s  .c o  m
        final DateTime begin = tsdata.stream().map(TimeSeriesCollection::getTimestamp)
                .min(Comparator.naturalOrder()).orElseGet(() -> new DateTime(DateTimeZone.UTC));
        final DateTime end = tsdata.stream().map(TimeSeriesCollection::getTimestamp)
                .max(Comparator.naturalOrder()).orElse(begin);

        try (XdrEncodingFileWriter xdr = new XdrEncodingFileWriter(
                wrapCompress(new FileChannelWriter(fd.get(), 0), compress))) {
            xdr.beginEncoding();
            // Write mime header.
            {
                tsfile_mimeheader hdr = new tsfile_mimeheader();
                hdr.magic = MAGIC;
                hdr.version_number = version_from_majmin(getMajor(), getMinor());
                hdr.xdrEncode(xdr);
            }
            // Write header describing the data range.
            {
                tsfile_header hdr = new tsfile_header();
                hdr.first = ToXdr.timestamp(begin);
                hdr.last = ToXdr.timestamp(end);
                hdr.xdrEncode(xdr);
            }
            for (TimeSeriesCollection tsd : tsdata)
                ToXdr.datapoints(tsd).xdrEncode(xdr);
            xdr.endEncoding();
        }
    } catch (OncRpcException ex) {
        throw new IOException(ex);
    }
}

From source file:com.groupon.lex.metrics.history.xdr.support.FileSupport1.java

@Override
public void create_file(TSDataVersionDispatch.Releaseable<FileChannel> fd,
        Collection<? extends TimeSeriesCollection> tsdata, boolean compress) throws IOException {
    try {/*from  w ww.ja v  a2 s  . c  om*/
        final DateTime begin = tsdata.stream().map(TimeSeriesCollection::getTimestamp)
                .min(Comparator.naturalOrder()).orElseGet(() -> new DateTime(DateTimeZone.UTC));
        final DateTime end = tsdata.stream().map(TimeSeriesCollection::getTimestamp)
                .max(Comparator.naturalOrder()).orElse(begin);
        final ToXdr to_xdr_ = new ToXdr(new FromXdr());

        try (XdrEncodingFileWriter xdr = new XdrEncodingFileWriter(
                wrapCompress(new FileChannelWriter(fd.get(), 0), compress))) {
            xdr.beginEncoding();
            // Write mime header.
            {
                tsfile_mimeheader hdr = new tsfile_mimeheader();
                hdr.magic = MAGIC;
                hdr.version_number = version_from_majmin(getMajor(), getMinor());
                hdr.xdrEncode(xdr);
            }
            // Write header describing the data range.
            {
                tsfile_header hdr = new tsfile_header();
                hdr.first = ToXdr.timestamp(begin);
                hdr.last = ToXdr.timestamp(end);
                hdr.xdrEncode(xdr);
            }
            for (TimeSeriesCollection tsd : tsdata)
                to_xdr_.data(tsd).xdrEncode(xdr);
            xdr.endEncoding();
        }
    } catch (OncRpcException ex) {
        throw new IOException(ex);
    }
}

From source file:com.harpatec.examples.converter.DateTimeWriteConverter.java

License:Apache License

@Override
public DBObject convert(DateTime source) {
    DBObject dbo = new BasicDBObject();
    dbo.put("millis", source.getMillis());
    dbo.put("formatted", source.toDateTime(DateTimeZone.UTC).toString());
    return dbo;// www  . j av a  2 s.c  o m
}