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

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

Introduction

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

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:com.tremolosecurity.scale.ui.reports.ReportViewer.java

License:Apache License

public String runReport(ReportInformation ri) {
    try {/*w  w  w. j a  v  a  2 s.  c  o m*/
        this.reportInfo = ri;
        this.beginDate = null;
        this.endDate = null;
        this.userKey = null;
        this.error = null;
        this.paramError = null;
        this.results = null;
        this.runDateTime = null;
        this.reportLoaded = false;

        DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM dd, yyyy HH:mm:ss zzz");
        this.runDateTime = fmt.print(System.currentTimeMillis());

        if (ri.getParameters().size() == 0
                || (ri.getParameters().size() == 1 && ri.getParameters().contains("currentUser"))) {
            //no need for the parameters screen
            return "reportWait.xhtml";
        } else {
            return "reportParams.xhtml";
        }
    } catch (Throwable t) {
        this.error = "There was a problem loading the report";
        logger.error("Error loading report : " + ri.getName(), t);
        return "showReport.xhtml";
    }
}

From source file:com.tremolosecurity.scale.ui.reports.ReportViewer.java

License:Apache License

public String getEndDateLabel() {
    if (this.endDate == null) {
        return "Not Selected";
    } else {/*w w  w. j a v  a2  s.  com*/

        DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM dd, yyyy");
        return fmt.print(this.endDate.getTime());
    }
}

From source file:com.tremolosecurity.scale.ui.reports.ReportViewer.java

License:Apache License

public String getBeginDateLabel() {
    if (this.beginDate == null) {
        return "Not Selected";
    } else {// w  w  w .  ja va  2s. co m

        DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM dd, yyyy");
        return fmt.print(this.beginDate.getTime());
    }
}

From source file:com.trifork.stamdata.importer.jobs.cpr.CPRParser.java

License:Mozilla Public License

private static Date parseDateAndCheckValidity(String dateString, DateTimeFormatter format, String line)
        throws ParseException, Exception {
    dateString = fixWeirdDate(dateString);
    LocalDateTime date = format.parseLocalDateTime(dateString);
    String formattedDate = format.print(date);

    if (!formattedDate.equals(dateString)) {
        String errorMessage = "Ugyldig dato: " + dateString + " fra linjen [" + line + "]";

        if (haltOnDateErrors) {
            throw new Exception(errorMessage);
        } else {//from   w w  w. j a  v  a2s  . c  o m
            logger.error(errorMessage);
        }
    }

    return date.toDate();
}

From source file:com.trifork.stamdata.importer.util.Dates.java

License:Mozilla Public License

public static String toDateStringISO8601(Date date) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
    return formatter.print(date.getTime());
}

From source file:com.trifork.stamdata.importer.util.Dates.java

License:Mozilla Public License

public static String toFilenameDatetime(Date date) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH-mm-ss");
    return formatter.print(date.getTime());
}

From source file:com.trifork.stamdata.importer.util.Dates.java

License:Mozilla Public License

@Deprecated
public static String toSqlDate(Date date) {
    Preconditions.checkNotNull(date);/*from   w  w w. j a v  a  2 s.co  m*/
    DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    return df.print(date.getTime());
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

License:Apache License

/**
 * Uses the given formatter to create a calendar object from the timestamp
 * @param timestamp/*from   w ww.ja  va 2 s .  co  m*/
 * @param formatter
 * @return
 */
public static Calendar formattedTimestampToCalendar(String timestamp, DateTimeFormatter formatter) {
    long millis = 0;
    try {
        millis = formatter.parseMillis(timestamp);
        return fromMilliseconds(millis);
    } catch (IllegalArgumentException e) {
        // Turns out MYSQL timestamps can sometimes contain milliseconds, and sometimes not.
        // Regular Java date parsing is insensitive to that, but Joda refuses to parse with a
        // non-matching format. Hence, the ugliness below.
        // Formatters don't define a legit equals method, so we just check if they format the
        // current timestamp to the same string.
        long ts = System.currentTimeMillis();
        if (formatter.print(ts).equals(MYSQL_TIMESTAMP_FORMATTER.print(ts))) {
            return formattedTimestampToCalendar(timestamp, MYSQL_TIMESTAMP_FORMATTER_MILLIS);
        } else {
            // SUPPRESS CHECKSTYLE string multiple times
            LOG.debug("Could not parse date " + timestamp + " with dateformat " + formatter, e);
            return null;
        }
    }
}

From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java

License:Open Source License

/**
 * Convert to local time.//from w w w.j a v  a2s  .com
 *
 * @param timeOffset the time offset
 * @param time the time
 * @return the string
 */
public String convertToLocalTime(String timeOffset, String time) {
    Integer offsetValue = Integer.parseInt(timeOffset);

    log.debug("Offset value = " + offsetValue);
    DateTimeZone systemTimeZone = DateTimeZone.getDefault();
    log.debug("system time zone " + systemTimeZone.toString());
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTime systemDateTime = formatter.parseDateTime(time);
    log.debug("system date time " + systemDateTime.toString());
    systemDateTime = systemDateTime.withZoneRetainFields(systemTimeZone);
    log.debug("system date time after adding systemtimezone === " + systemDateTime.toString());

    int hours = -1 * offsetValue / 60;
    int minutes = offsetValue % 60;
    minutes = Math.abs(minutes);

    DateTimeZone localTimeZone = DateTimeZone.forOffsetHoursMinutes(hours, minutes);

    log.debug("Local time zone ==== " + localTimeZone.toString());

    DateTime convertedDateTime = systemDateTime.withZone(localTimeZone);

    String convertedDateTimeString = formatter.print(convertedDateTime);

    log.debug("converted time  :" + convertedDateTimeString);

    return convertedDateTimeString;

}

From source file:com.yandex.money.api.model.showcase.components.uicontrols.Date.java

License:Open Source License

private static DateTime parse(String dateTime, DateTimeFormatter formatter) {
    return dateTime.equals("now") ? DateTime.parse(formatter.print(DateTime.now()), formatter)
            : DateTime.parse(dateTime, formatter);
}