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:beans.utilidades.MetodosGenerales.java

public String esFecha(String f, String format) {
    /*/*  w ww  . j  a  va2 s .c o m*/
     *  null=invalido ""=aceptado pero vacio "valor"=aceptado (valor para db)
     */
    if (f.trim().length() == 0) {
        return "";
    }
    try {
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
        DateTimeFormatter fmt2 = DateTimeFormat.forPattern(format);
        DateTime the_date = DateTime.parse(f, fmt2);//trata de convertir al formato "format"(me llega por parametro)
        return fmt.print(the_date);//lo imprime en el formato "yyyy-MM-dd"
    } catch (Throwable ex) {
        return null;//invalida
    }
}

From source file:br.com.objectos.blog.PostImpl.java

License:Apache License

@Override
public String getPath() {
    DateTime date = getDate();//from   www  .  j a v a 2 s.c  o  m
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd");
    String directoryName = formatter.print(date);

    String title = getTitle();
    String filename;
    filename = Strings.accentsToAscii(title).alphanum().whitespaceTo("_").toString().toLowerCase();

    return directoryName + "/" + filename + ".html";
}

From source file:br.com.objectos.blog.PostImpl.java

License:Apache License

private void writeTo0(PostTemplate template, File destination) throws IOException {

    String html = render(template);

    DateTime date = getDate();//from  w ww .j  av  a2s .  c  o m
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd");
    String directoryName = formatter.print(date);

    File directory = new File(destination, directoryName);
    directory.mkdirs();

    String title = getTitle();
    String filename = Strings.accentsToAscii(title).alphanum().whitespaceTo("_").toString().toLowerCase();

    File file = new File(directory, filename + ".html");
    Files.write(html, file, Charsets.UTF_8);

}

From source file:br.com.objectos.blog.PostTemplateImpl.java

License:Apache License

@Override
public void setDate(DateTime date) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
    tryToSet(PostTag.DATE, formatter.print(date));
}

From source file:brickhouse.udf.date.AddISOPeriodUDF.java

License:Apache License

public String evaluate(String dateString, String dateFormat, String periodString) {
    if (dateString == null) {
        return null;
    }/*from  w ww.j ava  2 s  . c o m*/

    if (dateFormat == null) {
        dateFormat = "YYYY-MM-dd HH:mm:ss";
    }

    DateTimeFormatter dateFormatter = org.joda.time.format.DateTimeFormat.forPattern(dateFormat);
    DateTime input = dateFormatter.parseDateTime(dateString);

    Duration duration = periodFormatter.parsePeriod(periodString).toStandardDuration();
    long seconds = duration.getStandardSeconds();

    DateTime output = input.plusSeconds(Long.valueOf(seconds).intValue());
    return dateFormatter.print(output);
}

From source file:brickhouse.udf.date.DateFormatUDF.java

License:Apache License

public String evaluate(String dt, String fromFormatString, String toFormatString) {
    DateTimeFormatter fromFormatter = org.joda.time.format.DateTimeFormat.forPattern(fromFormatString);
    DateTimeFormatter toFormatter = org.joda.time.format.DateTimeFormat.forPattern(toFormatString);

    DateTime fromDt = fromFormatter.parseDateTime(dt);
    String formatted = toFormatter.print(fromDt);
    return formatted;
}

From source file:ca.phon.phon2csv.SessionInfoColumn.java

License:Open Source License

@Override
public String getData(Session t, Record utt) {
    String retVal = "";

    if (field.equalsIgnoreCase("Name")) {
        retVal = t.getCorpus() + "." + t.getName();
    } else if (field.equalsIgnoreCase("Corpus")) {
        retVal = t.getCorpus();/*ww w . ja  v a2  s  . c  o  m*/
    } else if (field.equalsIgnoreCase("ID")) {
        retVal = t.getName();
    } else if (field.equalsIgnoreCase("Media")) {
        retVal = (t.getMediaLocation() != null ? t.getMediaLocation() : "");
    } else if (field.equalsIgnoreCase("Date")) {
        if (t.getDate() != null) {
            final DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
            retVal = dateFormatter.print(t.getDate());
        }
    } else {
        retVal = "";
    }
    return retVal;
}

From source file:ca.phon.phon2csv.SpeakerInfoColumn.java

License:Open Source License

@Override
public String getData(Session t, Record utt) {
    Participant speaker = utt.getSpeaker();
    if (speaker != null) {
        String retVal = "";
        if (field.equalsIgnoreCase("name")) {
            retVal = speaker.toString();
        } else if (field.equalsIgnoreCase("age")) {
            if (t.getDate() != null && speaker.getBirthDate() != null) {
                final AgeFormatter ageFormatter = new AgeFormatter();
                retVal = ageFormatter.format(speaker.getAge(t.getDate()));
            }//  ww  w .jav a2s .  com
        } else if (field.equalsIgnoreCase("education")) {
            retVal = speaker.getEducation();
        } else if (field.equalsIgnoreCase("language")) {
            retVal = speaker.getLanguage();
        } else if (field.equalsIgnoreCase("group")) {
            retVal = speaker.getGroup();
        } else if (field.equalsIgnoreCase("sex")) {
            if (speaker.getSex() != null) {
                retVal = speaker.getSex().toString();
            }
        } else if (field.equalsIgnoreCase("role")) {
            retVal = speaker.getRole().getTitle();
        } else if (field.equalsIgnoreCase("birthday")) {
            if (speaker.getBirthDate() != null) {
                final DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
                retVal = dateFormatter.print(speaker.getBirthDate());
            }
        } else {
            retVal = "";
        }
        return retVal;
    } else {
        return "";
    }
}

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

License:Open Source License

/**
 * Convert {@link DateTime} objects to string
 * /* w w w.  j  av  a 2  s. c om*/
 * @param dateTime
 * 
 * @return text
 */
public static String dateTimeToString(DateTime dateTime) {
    final DateTimeFormatter formatter = createFormatter();
    return formatter.print(dateTime);
}

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

License:Open Source License

/**
 * Format this datetime using the given formatter.
 * /*w w  w .  j  a va 2  s .com*/
 * @param fmt  the formatter
 * @return     the string representation
 */
public String toString(DateTimeFormatter fmt) {
    return fmt.print(data);
}