Example usage for org.joda.time DateTimeZone convertLocalToUTC

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

Introduction

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

Prototype

public long convertLocalToUTC(long instantLocal, boolean strict) 

Source Link

Document

Converts a local instant to an actual UTC instant with the same local time.

Usage

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Gets the UTC time from local.//  w w  w.  ja  va 2 s.c om
 * 
 * @param localTimeInMillis the local time in millis
 * @param timeZone the time zone
 * @return the UTC time from local
 */
public static long getUTCTimeFromLocal(long localTimeInMillis, String timeZone) {

    long utcTime = 0;
    DateTimeZone dateTimeZone = DateTimeZone.forID(timeZone);
    utcTime = dateTimeZone.convertLocalToUTC(localTimeInMillis, false);
    return utcTime;
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Gets the uTC time from local./*from w  w  w. j  a v a  2  s.c  o  m*/
 * @param localTimeInMillis the local time in millis
 * @param timeZone the time zone
 * @return the uTC time from local
 */
public static long getUTCTimeFromLocal(long localTimeInMillis, String timeZone) {

    System.out.println("Time Zone 2 = " + timeZone);
    long utcTime = 0;
    DateTimeZone dateTimeZone = DateTimeZone.forID(timeZone);
    utcTime = dateTimeZone.convertLocalToUTC(localTimeInMillis, false);
    System.out.println(dateTimeZone);
    return utcTime;
}

From source file:com.facebook.presto.hive.GenericHiveRecordCursor.java

License:Apache License

private static long getLongOrTimestamp(Object value, DateTimeZone hiveTimeZone) {
    if (value instanceof Timestamp) {
        // The Hive SerDe parses timestamps using the default time zone of
        // this JVM, but the data might have been written using a different
        // time zone. We need to convert it to the configured time zone.

        // the timestamp that Hive parsed using the JVM time zone
        long parsedJvmMillis = ((Timestamp) value).getTime();

        // remove the JVM time zone correction from the timestamp
        DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
        long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);

        // convert to UTC using the real time zone for the underlying data
        long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);

        return utcMillis;
    }//from   ww  w .ja  v a  2s .c  om
    return ((Number) value).longValue();
}

From source file:com.sandata.lab.common.utils.date.DateUtil.java

License:Open Source License

public static Date ConvertDateToUTC(Date localDate) throws ParseException {
    DateTimeZone tz = DateTimeZone.getDefault();
    Date utcDate = new Date(tz.convertLocalToUTC(localDate.getTime(), false));
    return utcDate;
}

From source file:eu.europa.ec.fisheries.uvms.common.DateUtils.java

License:Open Source License

public static Date getNowDateUTC() {
    DateTimeZone zone = DateTimeZone.getDefault();
    long utc = zone.convertLocalToUTC(new Date().getTime(), false);
    return new Date(utc);
}

From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java

License:Open Source License

public static Date parsePositionTime(XMLGregorianCalendar positionTime) {
    if (positionTime != null) {
        DateTimeZone localTZ = DateTimeZone.getDefault();
        long eventMillsInUTCTimeZone = localTZ
                .convertLocalToUTC(positionTime.toGregorianCalendar().getTime().getTime(), false);
        DateTime evenDateTimeInUTCTimeZone = new DateTime(eventMillsInUTCTimeZone);
        return evenDateTimeInUTCTimeZone.toDate();
    }//from  w ww  .  j  av  a 2 s .co m
    return null;
}

From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java

License:Open Source License

public static Date convertDateTimeInUTC(String dateTimeInUTC, String pattern) {
    if (dateTimeInUTC != null) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {//from   www. jav a2  s  . c o m
            Date theDate = sdf.parse(dateTimeInUTC);
            DateTimeZone localTZ = DateTimeZone.getDefault();
            long eventMillsInUTCTimeZone = localTZ.convertLocalToUTC(theDate.getTime(), false);
            DateTime evenDateTimeInUTCTimeZone = new DateTime(eventMillsInUTCTimeZone);
            return evenDateTimeInUTCTimeZone.toDate();
        } catch (java.text.ParseException e) {
            LOG.info("Could not parse dateTimeInUTC: " + dateTimeInUTC + " with pattern: " + pattern
                    + ". Trying next pattern");
        }
    }
    return null;
}

From source file:io.confluent.connect.hdfs.partitioner.TimeBasedPartitioner.java

License:Apache License

public static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimeStamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimeStamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}

From source file:io.confluent.connect.hdfs.partitioner.TimeUtils.java

License:Apache License

private static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimeStamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimeStamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}

From source file:io.confluent.connect.storage.partitioner.TimeBasedPartitioner.java

License:Open Source License

public static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimestamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimestamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}