Example usage for org.joda.time DateTime getMillis

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

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:ch.ge.ve.commons.fileutils.OutputFilesPattern.java

License:Open Source License

private String getDateAsString(DateTime date) {
    return dateFormat.format(date.getMillis());
}

From source file:ch.ge.ve.commons.fileutils.OutputFilesPattern.java

License:Open Source License

private String getDateTimeAsString(DateTime date) {
    return datetimeFormat.format(date.getMillis());
}

From source file:ch.icclab.cyclops.client.CloudStackPuller.java

License:Open Source License

/**
 * Will determine when was the last entry point (pull from CloudStack), or even if there was any
 *
 * @return date object of the last commit, or epoch if there was none
 *//*  www .j ava  2s. c o m*/
private DateTime whenWasLastPull() {
    DateTime last;

    LatestPullORM pull = (LatestPullORM) HibernateClient.getInstance().getObject(LatestPullORM.class, 1l);
    if (pull == null) {
        last = new DateTime(0);
    } else {
        last = new DateTime(pull.getTimeStamp());
    }

    logger.trace("Getting the last pull date " + last.toString());

    // get date specified by admin
    String date = settings.getCloudStackImportFrom();
    if (date != null && !date.isEmpty()) {
        try {
            logger.trace("Admin provided us with import date preference " + date);
            DateTime selection = Time.getDateForTime(date);

            // if we are first time starting and having Epoch, change it to admin's selection
            // otherwise skip admin's selection and continue from the last DB entry time
            if (last.getMillis() == 0) {
                logger.debug("Setting first import date as configuration file dictates.");
                last = selection;
            }
        } catch (Exception ignored) {
            // ignoring configuration preference, as admin didn't provide correct format
            logger.debug("Import date selection for CloudStack ignored - use yyyy-MM-dd format");
        }
    }

    return last;
}

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// w w  w  .  j  a 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: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 ww w  .  ja  va2 s .  c om*/
 * @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.client.CloudStackPuller.java

License:Open Source License

/**
 * Will determine when was the last entry point (pull from CloudStack), or even if there was any
 *
 * @return date object of the last commit, or epoch if there was none
 *//* www . j a v  a 2  s.co  m*/
private DateTime whenWasLastPull() {
    DateTime last = new InfluxDBClient().getLastPull();
    logger.trace("Getting the last pull date " + last.toString());

    // get date specified by admin
    String date = settings.getCloudStackImportFrom();
    if (date != null && !date.isEmpty()) {
        try {
            logger.trace("Admin provided us with import date preference " + date);
            DateTime selection = Time.getDateForTime(date);

            // if we are first time starting and having Epoch, change it to admin's selection
            // otherwise skip admin's selection and continue from the last DB entry time
            if (last.getMillis() == 0) {
                logger.debug("Setting first import date as configuration file dictates.");
                last = selection;
            }
        } catch (Exception ignored) {
            // ignoring configuration preference, as admin didn't provide correct format
            logger.debug("Import date selection for CloudStack ignored - use yyyy-MM-dd format");
        }
    }

    return last;
}

From source file:ch.icclab.cyclops.support.database.influxdb.client.InfluxDBClient.java

License:Open Source License

/**
 * Save a log into database with message with what happened
 * @param date that has to be marked to DB
 * @param eventType of what is being logged
 *///from   w w  w .  j  ava  2s.  c  o m
public void saveLog(DateTime date, String eventType) {
    InfluxDB db = getConnection();

    Point point = Point.measurement(cloudStackEvents).time(date.getMillis(), TimeUnit.MILLISECONDS)
            .field("event", eventType).build();

    db.write(logsDb, "default", point);
}

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/*w w  w  .j  a  v a 2 s .c  o  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.DateInterval.java

License:Open Source License

/**
 * Will determine when was the last entry point (pull from Ceilometer), or even if there was any
 *
 * @return date object of the last commit, or epoch if there was none
 *///from  w w w .j av  a2s.c  o m

private DateTime whenWasLastPull() {
    DateTime last;

    LatestPullORM pull = (LatestPullORM) HibernateClient.getInstance().getObject(LatestPullORM.class, 1l);
    if (pull == null) {
        last = new DateTime(0);
    } else {
        last = new DateTime(pull.getTimeStamp());
    }

    logger.trace("Getting the last pull date " + last.toString());

    // get date specified by admin
    String date = Loader.getSettings().getOpenStackSettings().getFirstImport();
    if (date != null && !date.isEmpty()) {
        try {
            logger.trace("Admin provided us with import date preference " + date);
            DateTime selection = Time.getDateForTime(date);

            // if we are first time starting and having Epoch, change it to admin's selection
            // otherwise skip admin's selection and continue from the last DB entry time
            if (last.getMillis() == 0) {
                logger.debug("Setting first import date as configuration file dictates.");
                last = selection;
            }
        } catch (Exception ignored) {
            // ignoring configuration preference, as admin didn't provide correct format
            logger.debug("Import date selection for Ceilometer ignored - use yyyy-MM-dd'T'HH:mm:ssZ format");
        }
    }
    DateTime dateTime = last.toDateTime(DateTimeZone.UTC);
    return dateTime;
}

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/*from   www.ja  v  a  2  s.  c  o  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();
}