Example usage for org.joda.time.format DateTimeFormatter parseDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseDateTime.

Prototype

public DateTime parseDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new DateTime.

Usage

From source file:ca.phon.session.DateFormatter.java

License:Open Source License

/**
 * Convert a string to a {@link DateTime} object
 * //from   ww  w  . ja va2 s.c o  m
 * @param text
 * 
 * @return dateTime
 * 
 * @throws IllegalArgumentException
 */
public static DateTime stringToDateTime(String text) {
    final DateTimeFormatter formatter = createFormatter();
    return formatter.parseDateTime(text);
}

From source file:cc.vidr.datum.term.DateTimeTerm.java

License:Open Source License

/**
 * Create a new term from the given string using the given parser.
 * /*from   w  ww  .j av  a 2  s .c  o m*/
 * @param text  the string
 * @param fmt   the parser
 */
public DateTimeTerm(String text, DateTimeFormatter fmt) {
    this(fmt.parseDateTime(text));
}

From source file:ch.admin.suis.msghandler.util.ISO8601Utils.java

License:Open Source License

/**
 * Parse the given string in the ISO-8601 format and returns the resulting
 * date. If the provided value is <code>null</code>, this method returns
 * <code>null</code> as well.
 *
 * @param value must be a string in the ISO-8601 format
 * @return the created <code>java.util.Date</code> object
 * @throws IllegalArgumentException      if the provided parameter value is not a string in the ISO-8601
 *                                       format
 * @throws UnsupportedOperationException if parsing is not supported
 *//*from  w  ww  . j  a  v a2  s  . c om*/
public static Date parse(String value) {
    if (null == value) {
        return null;
    }
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser();
    return fmt.parseDateTime(value).toDate();
}

From source file:ch.icclab.cyclops.model.ceilometerMeasurements.AbstractOpenStackCeilometerUsage.java

License:Open Source License

/**
 * Will compute number of milliseconds from epoch to startDate
 *
 * @param time as string//from www.j a v  a2 s. co  m
 * @return milliseconds since epoch
 */
public static long getMilisForTime(String time) {
    // first we have to get rid of 'T', as we need just T
    String isoFormat = time.replace("'", "");

    // then we have to create proper formatter
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
            .withLocale(Locale.ROOT).withChronology(ISOChronology.getInstanceUTC());

    // and now parse it
    DateTime dt = formatter.parseDateTime(isoFormat);

    return dt.getMillis();
}

From source file:ch.icclab.cyclops.model.UsageData.java

License:Open Source License

/**
 * Will compute number of milliseconds from epoch to startDate
 *
 * @param time as string//from  www  . ja v a 2s .  co  m
 * @return milliseconds since epoch
 */
public static long getMilisForTime(String time) {
    // first we have to get rid of 'T', as we need just T
    String isoFormat = time.replace("'", "");

    // then we have to create proper formatter
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withLocale(Locale.ROOT)
            .withChronology(ISOChronology.getInstanceUTC());

    // and now parse it
    DateTime dt = formatter.parseDateTime(isoFormat);

    return dt.getMillis();
}

From source file:ch.icclab.cyclops.services.iaas.cloudstack.util.Time.java

License:Open Source License

/**
 * This method computes the date of String time (with support for 'T' and time zones)
 *
 * @param full//from w ww  .  j  ava 2s .  c om
 * @return UTC DateTime object
 */
public static DateTime getDateForTime(String full) {
    String day = (full.contains("T")) ? full.substring(0, full.indexOf("T")) : full;

    // convert it to time object
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd").withLocale(Locale.ROOT)
            .withChronology(ISOChronology.getInstanceUTC());

    return formatter.parseDateTime(day);
}

From source file:ch.icclab.cyclops.services.iaas.cloudstack.util.Time.java

License:Open Source License

/**
 * Normalise date in string format/*from  ww w.jav  a  2  s. com*/
 *
 * @param original string
 * @return normalised string
 */
public static String normaliseString(String original) {
    try {
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").withLocale(Locale.ROOT)
                .withChronology(ISOChronology.getInstanceUTC());

        // and now parse it
        DateTime dt = formatter.parseDateTime(original);

        return dt.toString();

    } catch (Exception ignored) {
        return original;
    }
}

From source file:ch.icclab.cyclops.usecases.tnova.model.RevenueSharingEntry.java

License:Open Source License

/**
 * Will compute number of milliseconds from epoch to startDate
 *
 * @param time as string//from w w  w  .  j a  va2 s .  co m
 * @return milliseconds since epoch
 */
public static long getMillisForTime(String time) {
    // first we have to get rid of 'T', as we need just T
    String isoFormat = time.replace("'", "");

    // then we have to create proper formatter
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withLocale(Locale.ROOT)
            .withChronology(ISOChronology.getInstanceUTC());

    // and now parse it
    DateTime dt = formatter.parseDateTime(isoFormat);

    return dt.getMillis();
}

From source file:ch.icclab.cyclops.util.Time.java

License:Open Source License

/**
 * Will compute number of milliseconds from epoch to startDate
 *
 * @param time as string/*w  w  w.j av  a  2 s. co m*/
 * @return milliseconds since epoch
 */
public static long getMilisForTime(String time) {
    // first we have to get rid of 'T', as we need just T
    String isoFormat = time.replace("'", "");

    // then we have to create proper formatter
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").withLocale(Locale.ROOT)
            .withChronology(ISOChronology.getInstanceUTC());

    // and now parse it
    DateTime dt = formatter.parseDateTime(isoFormat);

    return dt.getMillis();
}

From source file:ch.icclab.cyclops.util.Time.java

License:Open Source License

/**
 * This method computes the date of String time (with support for 'T' and time zones)
 *
 * @param full/*ww w  . j a  va 2s .co m*/
 * @return UTC DateTime object
 */
public static DateTime getDateForTime(String full) {
    // convert it to time object
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").withLocale(Locale.ROOT)
            .withChronology(ISOChronology.getInstanceUTC());

    return formatter.parseDateTime(full);
}