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:net.bashtech.geobot.MessageReplaceParser.java

License:Open Source License

public static String handleDatetime(String message, String prefix, String suffix, String format) {

    int commandStart = message.indexOf(prefix);
    int commandEnd = message.indexOf(suffix);

    String replaced = message.substring(commandStart, commandEnd + suffix.length());

    DateTimeZone tz;//from  w w  w .  jav a2 s . co  m
    if (commandStart + prefix.length() < commandEnd) {
        String tzid = message.substring(commandStart + prefix.length(), commandEnd);
        try {
            tz = DateTimeZone.forID(tzid);
        } catch (IllegalArgumentException e) {
            tz = DateTimeZone.UTC;
        }
    } else {
        tz = DateTimeZone.UTC;
    }

    DateTimeFormatter fmt = DateTimeFormat.forPattern(format);
    fmt = fmt.withZone(tz);
    String dateStr = fmt.print(new DateTime());
    message = message.replace(replaced, dateStr);

    return message;
}

From source file:net.form105.rm.base.model.parameter.TimestampParameter.java

License:Apache License

@Override
public String getValueAsString() {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    return fmt.print(dateTime);
}

From source file:net.longfalcon.newsj.util.DateUtil.java

License:Open Source License

public static String formatDate(Date date, String format) {
    if (date == null) {
        return "Never";
    }//from   www .j  a  va 2s  .  c  o m
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(format);
    return dateTimeFormatter.print(new DateTime(date));
}

From source file:net.metanotion.exportimport.BasicInstanceExport.java

License:Apache License

private static String getStoreTime() {
    final DateTimeFormatter dateFormat = DateTimeFormat.forPattern("YYYY.MM.dd-HH.mm");
    return dateFormat.print(new DateTime());
}

From source file:net.mobid.codetraq.utils.Utilities.java

License:Open Source License

/**
 * Returns a formatted time of the current time. The format is "yyyy-MM-dd at hh:mm AM/PM".
 * @return a <code>String</code> that represents the current time
 *//*from www  .j ava 2s  .c  o  m*/
public static String getFormattedTime() {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd 'at' hh:mm aaa");
    return formatter.print(Calendar.getInstance().getTimeInMillis());
}

From source file:net.mobid.codetraq.utils.Utilities.java

License:Open Source License

/**
 * Returns a formatted time of the time specified by the timestamp. The format is
 * "yyyy-MM-dd at hh:mm AM/PM"./*  w ww.  j  a va2 s  .  c  om*/
 * @param millis - timestamp that specified a certain time
 * @return a <code>String</code> that represents the current time
 */
public static String getFormattedTime(long millis) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd 'at' hh:mm aaa");
    return formatter.print(millis);
}

From source file:net.simonvt.cathode.api.util.TimeUtils.java

License:Apache License

public static String getIsoTime() {
    DateTime dt = new DateTime();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();
    return fmt.print(dt);
}

From source file:net.simonvt.cathode.api.util.TimeUtils.java

License:Apache License

public static String getIsoTime(long millis) {
    DateTime dt = new DateTime(millis);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();
    return fmt.print(dt);
}

From source file:net.solarnetwork.util.JodaDateFormatEditor.java

License:Open Source License

@Override
public String getAsText() {
    Object val = getValue();
    if (val == null) {
        return null;
    }//w  w w.jav  a2  s . co m
    DateTimeFormatter format = this.dateFormatters[0];
    if (val instanceof ReadableInstant) {
        return format.print((ReadableInstant) val);
    } else if (val instanceof ReadablePartial) {
        return format.print((ReadablePartial) val);
    } else if (val instanceof Date) {
        return format.print(((Date) val).getTime());
    } else if (val instanceof Calendar) {
        return format.print(((Calendar) val).getTimeInMillis());
    }
    throw new IllegalArgumentException("Unsupported date object [" + val.getClass() + "]: " + val);
}

From source file:net.sourceforge.fenixedu.dataTransferObject.resourceAllocationManager.OccupationPeriodBean.java

License:Open Source License

public String getDatesString() {
    if (intervals.size() == 0 || occupationPeriod == null) {
        return BundleUtil.getString(Bundle.RESOURCE_ALLOCATION, "label.periods.no.dates");
    }// w w  w .  j  a va 2  s.  c o  m

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM").withLocale(I18N.getLocale());

    StringBuilder builder = new StringBuilder();

    for (Interval interval : getIntervals()) {

        if (builder.length() > 0) {
            builder.append(", ");
        }

        builder.append(formatter.print(interval.getStart()));

        builder.append(" - ");

        builder.append(formatter.print(interval.getEnd()));

    }

    return builder.toString();

}