Example usage for org.joda.time LocalDateTime toDateTime

List of usage examples for org.joda.time LocalDateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toDateTime.

Prototype

public DateTime toDateTime(DateTimeZone zone) 

Source Link

Document

Converts this object to a DateTime using the specified zone.

Usage

From source file:org.openhat.opdi.units.UnitFormat.java

License:Open Source License

public long convertFromLocalDate(LocalDateTime date) {
    if ("unixSeconds".equals(conversion)) {
        DateTime utc = date.toDateTime(DateTimeZone.UTC);
        return utc.getMillis() / 1000;
    } else if ("unixSecondsLocal".equals(conversion)) {
        DateTime utc = date.toDateTime();
        return utc.getMillis() / 1000;
    } else/*from  w w w  .j  a va 2 s . co m*/
        throw new RuntimeException("UnitFormat: Conversion not supported: " + conversion);
}

From source file:org.openlmis.referencedata.JaVersDateProvider.java

License:Open Source License

/**
 * Converts the specified LocalDateTime to a ZonedDateTime in UTC.
 */// w  ww  .j av a2  s  . c  o m
public static ZonedDateTime getZonedDateTime(LocalDateTime localDateTime) {

    /* Get an instant representing localDateTime with the understanding that it was stored
       using JaVersDateProvider.DATE_TIME_ZONE */
    long epoch = localDateTime.toDateTime(DATE_TIME_ZONE).getMillis();
    Instant instant = Instant.ofEpochMilli(epoch);

    //Convert the instant to a ZonedDateTime in UTC.
    return ZonedDateTime.ofInstant(instant, ZONE_ID);
}