Example usage for org.joda.time DateTime toDateTime

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

Introduction

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

Prototype

public DateTime toDateTime(Chronology chronology) 

Source Link

Document

Get this object as a DateTime, returning this if possible.

Usage

From source file:org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils.java

License:Open Source License

public static DateTime parseDate(String format, DateTimeZone timeZone) {
    DateTime dateTime = dateTimeFormatter.parser().parseDateTime(format);
    return timeZone != null ? dateTime.toDateTime(timeZone) : dateTime;
}

From source file:org.fenixedu.cms.ui.CMSBean.java

License:Open Source License

public String prettyDate(DateTime date) {
    long time = date.toDate().getTime();

    Date javaUtilDate = date.toDateTime(DateTimeZone.UTC).toDate();

    return new PrettyTime(I18N.getLocale()).format(javaUtilDate);
}

From source file:org.fuin.axon.support.base.JodaDateTimeSerializer.java

License:Apache License

@Override
protected final void writeValue(final AbstractHessianOutput out, final Object obj) throws IOException {
    final DateTime dateTime = (DateTime) obj;
    final long millis = dateTime.toDateTime(DateTimeZone.UTC).getMillis();
    out.writeUTCDate(millis);/* www. j  a  va2s .com*/
}

From source file:org.gravidence.gravifon.util.DateTimeUtils.java

License:Open Source License

/**
 * Converts datetime object to array of UTC datetime fields.<p>
 * Given datetime object is casted to UTC.<p>
 * Resulting array content is as follows: <code>[yyyy,MM,dd,HH,mm,ss,SSS]</code>.
 * /* ww w  .  java2s .  c o m*/
 * @param value datetime object
 * @return array of UTC datetime fields
 */
public static int[] dateTimeToArray(DateTime value) {
    int[] result;

    if (value == null) {
        result = null;
    } else {
        result = new int[7];

        DateTime valueUTC = value.toDateTime(DateTimeZone.UTC);

        result[0] = valueUTC.getYear();
        result[1] = valueUTC.getMonthOfYear();
        result[2] = valueUTC.getDayOfMonth();
        result[3] = valueUTC.getHourOfDay();
        result[4] = valueUTC.getMinuteOfHour();
        result[5] = valueUTC.getSecondOfMinute();
        result[6] = valueUTC.getMillisOfSecond();
    }

    return result;
}

From source file:org.gravidence.gravifon.util.DateTimeUtils.java

License:Open Source License

/**
 * Converts datetime object to JSON array node.<p>
 * Given datetime object is casted to UTC.
 * //  w  ww . j  a  v  a 2s .  com
 * @param value datetime object
 * @return JSON array node (UTC)
 */
public static ArrayNode dateTimeToArrayNode(DateTime value) {
    ArrayNode result;

    if (value == null) {
        result = null;
    } else {
        DateTime valueUTC = value.toDateTime(DateTimeZone.UTC);

        result = SharedInstanceHolder.OBJECT_MAPPER.valueToTree(DateTimeUtils.dateTimeToArray(valueUTC));
    }

    return result;
}

From source file:org.graylog2.restclient.lib.DateTools.java

License:Open Source License

public static DateTime inUserTimeZone(DateTime timestamp) {
    DateTimeZone tz = globalTimezone;/*from w w w . j a  v a 2s.c om*/
    final User currentUser = UserService.current();
    if (currentUser != null && currentUser.getTimeZone() != null) {
        tz = currentUser.getTimeZone();
    }
    return timestamp.toDateTime(tz);
}

From source file:org.ireas.mediawiki.MediaWikiUtils.java

License:Open Source License

/**
 * Converts the specified date to a timestamp in the MediaWiki API format
 * and in the UTC time zone./* www  .ja va  2  s .  c  om*/
 *
 * @param date the date to convert
 * @return the specified date as a UTC timestamp
 */
public static String formatApiDate(final DateTime date) {
    Preconditions.checkNotNull(date);

    return API_TIMESTAMP_FORMAT.print(date.toDateTime(DateTimeZone.UTC));
}

From source file:org.jahia.taglibs.functions.Functions.java

License:Open Source License

public static String formatISODate(java.lang.String dateToParse, String pattern, Locale locale) {
    try {//w ww .  j  a v  a 2 s .  co m
        DateTime dateTime = ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(dateToParse);
        return DateTimeFormat.forPattern(pattern).withLocale(locale != null ? locale : Locale.ENGLISH)
                .print(!dateToParse.endsWith("Z") ? dateTime : dateTime.toDateTime(DateTimeZone.forID("UTC")));
    } catch (Exception e) {
        logger.debug("Unable to parse date:" + dateToParse, e);
        return null;
    }
}

From source file:org.jevis.commons.driver.TimeConverter.java

License:Open Source License

public static DateTime convertTime(DateTimeZone from, DateTime time) {
    long timeInMillis = time.getMillis();
    DateTime dateTime = new DateTime(timeInMillis, from);
    DateTime tmpTime = dateTime;
    dateTime = tmpTime.toDateTime(DateTimeZone.UTC);
    return dateTime;
}

From source file:org.jpos.transaction.TxnId.java

License:Open Source License

/**
 * Creates new TxnId object/*from  w ww.ja v  a 2s .c  o  m*/
 *
 * @param dt Transaction's TIMESTAMP DateTime
 * @param node node id
 * @param transactionId TransactionManager's ID
 */
public static TxnId create(DateTime dt, int node, long transactionId) {
    TxnId id = new TxnId();
    if (dt.getZone() != DateTimeZone.UTC)
        dt = dt.toDateTime(DateTimeZone.UTC);

    return id.init(dt.getYear() - 2000, dt.getDayOfYear(), dt.getSecondOfDay(), node, transactionId);
}