Example usage for org.joda.time DateTime withZone

List of usage examples for org.joda.time DateTime withZone

Introduction

In this page you can find the example usage for org.joda.time DateTime withZone.

Prototype

public DateTime withZone(DateTimeZone newZone) 

Source Link

Document

Returns a copy of this datetime with a different time zone, preserving the millisecond instant.

Usage

From source file:org.greencheek.related.indexing.util.JodaUTCCurrentDateAndHourFormatter.java

License:Apache License

@Override
public String getCurrentDayAndHour() {
    DateTime dt = new DateTime();
    DateTime utc = dt.withZone(DateTimeZone.UTC);
    return formatter.print(utc);
}

From source file:org.greencheek.related.indexing.util.JodaUTCCurrentDateFormatter.java

License:Apache License

@Override
public String getCurrentDay() {
    DateTime dt = new DateTime();
    DateTime utc = dt.withZone(DateTimeZone.UTC);
    StringBuilderWriter b = new StringBuilderWriter(10);
    try {//from  w  ww .j a v  a 2 s  . c  o  m
        formatter.printTo(b, utc);
    } catch (IOException e) {
        // this does not get thrown by the StringBuilder Appendable interface.
    }
    return b.toString();
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnDateTimeMapper.java

License:Apache License

@Override
public DateTime fromNonNullValue(String s) {

    DateTime parsedDateTime = DATE_TIME_FORMATTER.parseDateTime(s);
    DateTimeZone correctTimeZone = parsedDateTime.getZone();
    DateTime utcDateTime = parsedDateTime.withZoneRetainFields(DateTimeZone.UTC);
    DateTime correctedDateTime = utcDateTime.withZone(correctTimeZone);
    return correctedDateTime;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnDateTimeMapper.java

License:Apache License

@Override
public String toNonNullValue(DateTime value) {

    DateTimeZone correctTimeZone = value.getZone();
    DateTime utcDateTime = value.withZone(DateTimeZone.UTC);
    DateTime utcDateTimeWithCorrectTimeZone = utcDateTime.withZoneRetainFields(correctTimeZone);
    String dateTimeAsString = DATE_TIME_FORMATTER.print(utcDateTimeWithCorrectTimeZone);
    return dateTimeAsString;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnDateTimeMapper.java

License:Apache License

@Override
public DateTime fromNonNullValue(Timestamp value) {

    DateTimeZone currentJavaZone = javaZone == null ? ZoneHelper.getDefault() : javaZone;

    DateTime dateTime = new DateTime(value.getTime());
    DateTime dateTimeWithZone = dateTime.withZone(currentJavaZone);

    return dateTimeWithZone;
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZone.java

License:Apache License

@Override
protected DateTime fromConvertedColumns(Object[] convertedColumns) {

    LocalDateTime datePart = (LocalDateTime) convertedColumns[0];
    DateTimeZone zone = (DateTimeZone) convertedColumns[1];

    DateTime result;

    if (datePart == null) {
        result = null;/*  www  .j  a va 2 s . co  m*/
    } else {
        result = datePart.toDateTime(databaseZone == null ? zone : databaseZone);

        if (databaseZone != null) {
            result = result.withZone(zone);
        }
    }

    return result;
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZone.java

License:Apache License

@Override
protected Object[] toConvertedColumns(DateTime value) {

    final DateTime myValue;
    if (databaseZone == null) {
        myValue = value;/*from  ww w  .ja  v a  2 s.  c o  m*/
    } else {
        myValue = value.withZone(databaseZone);
    }
    return new Object[] { myValue.toLocalDateTime(), value.getZone() };
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZoneWithOffset.java

License:Apache License

@Override
protected DateTime fromConvertedColumns(Object[] convertedColumns) {

    LocalDateTime datePart = (LocalDateTime) convertedColumns[0];
    DateTimeZoneWithOffset offset = (DateTimeZoneWithOffset) convertedColumns[1];

    DateTime result;

    if (datePart == null) {
        result = null;// ww w.j  a va2 s .c o  m
    } else {
        result = datePart.toDateTime(databaseZone == null ? offset.getStandardDateTimeZone() : databaseZone);

        if (databaseZone != null) {
            result = result.withZone(offset.getStandardDateTimeZone());
        }
    }

    // Handling DST rollover
    if (result != null && offset.getOffsetDateTimeZone() != null && offset.getStandardDateTimeZone()
            .getOffset(result) > offset.getOffsetDateTimeZone().getOffset(result)) {
        return result.withLaterOffsetAtOverlap();
    }

    return result;
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZoneWithOffset.java

License:Apache License

@Override
protected Object[] toConvertedColumns(DateTime value) {

    final DateTime myValue;
    if (databaseZone == null) {
        myValue = value;/*from   w ww  .java2  s .c o m*/
    } else {
        myValue = value.withZone(databaseZone);
    }
    return new Object[] { myValue.toLocalDateTime(),
            new DateTimeZoneWithOffset(value.getZone(), value.getZone().isFixed() ? null
                    : DateTimeZone.forOffsetMillis(value.getZone().getOffset(value))) };
}

From source file:org.jdesktop.swingx.DateTimePicker.java

License:LGPL

public void setDate(DateTime d) {
    super.setDate(d.withZone(DateTimeZone.forTimeZone(getTimeZone())).toDate());
}