Example usage for org.joda.time.format DateTimeFormatterBuilder DateTimeFormatterBuilder

List of usage examples for org.joda.time.format DateTimeFormatterBuilder DateTimeFormatterBuilder

Introduction

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

Prototype

public DateTimeFormatterBuilder() 

Source Link

Document

Creates a DateTimeFormatterBuilder.

Usage

From source file:JodaDT.java

License:Open Source License

/**
 * Creates a DateTime object from a String with this format
 * DD/MM/YYYY-hh:mm:ss./*from   w  ww .  jav a  2 s.  c o m*/
 *
 * @param date with format DD/MM/YYYY-hh:mm:ss
 * @return a DateTime object or null
 */
public static DateTime parseDDMMYYYYhhmmss(String date) {
    if (date != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        dtfb.appendLiteral(':');
        dtfb.appendMinuteOfHour(2);
        dtfb.appendLiteral(':');
        dtfb.appendSecondOfMinute(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        DateTime dt = dtf.parseDateTime(date);
        return dt;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Creates a DateTime object from a String with this format
 * DD/MM/YYYY-hh:mm.//from www .j  a v  a 2 s .c o  m
 *
 * @param date with format DD/MM/YYYY-hh:mm
 * @return a DateTime object or null
 */
public static DateTime parseDDMMYYYYhhmm(String date) {
    if (date != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        dtfb.appendLiteral(':');
        dtfb.appendMinuteOfHour(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        DateTime dt = dtf.parseDateTime(date);
        return dt;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Creates a DateTime object from a String with this format DD/MM/YYYY-hh
 *
 * @param date with format DD/MM/YYYY-hh
 * @return a DateTime object or null/*w w  w.  j  ava2 s . c  om*/
 */
public static DateTime parseDDMMYYYYhh(String data) {
    if (data != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        DateTime dt = dtf.parseDateTime(data);
        return dt;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Creates a DateTime object from a String with this format DD/MM/YYYY
 *
 * @param date with format DD/MM/YYYY//  w w  w .j  av a2  s  . com
 * @return a DateTime object or null
 */
public static DateTime parseDDMMYYYY(String data) {
    if (data != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        DateTimeFormatter dtf = dtfb.toFormatter();
        DateTime dt = dtf.parseDateTime(data);
        return dt;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Converts a DateTimeObject into a string with format DD/MM/YYYY-hh:mm:ss.
 *
 * @param dt a DateTime object/* w w  w .  j  a  v  a  2s  . c om*/
 * @return the formatted String or null
 */
public static String formatDDMMYYYYhhmmss(DateTime dt) {
    if (dt != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        dtfb.appendLiteral(':');
        dtfb.appendMinuteOfHour(2);
        dtfb.appendLiteral(':');
        dtfb.appendSecondOfMinute(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        String str = dt.toString(dtf);
        return str;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Converts a DateTimeObject into a string with format DD/MM/YYYY-hh:mm.
 *
 * @param dt a DateTime object/* w w  w.j  ava  2s.com*/
 * @return the formatted String or null
 */
public static String formatDDMMYYYYhhmm(DateTime dt) {
    if (dt != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        dtfb.appendLiteral(':');
        dtfb.appendMinuteOfHour(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        String str = dt.toString(dtf);
        return str;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Converts a DateTimeObject into a string with format DD/MM/YYYY-hh.
 *
 * @param dt a DateTime object//from  ww  w  .jav a 2  s. com
 * @return the formatted String or null
 */
public static String formatDDMMYYYYhh(DateTime dt) {
    if (dt != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        dtfb.appendLiteral('-');
        dtfb.appendHourOfDay(2);
        DateTimeFormatter dtf = dtfb.toFormatter();
        String str = dt.toString(dtf);
        return str;
    } else {
        return null;
    }
}

From source file:JodaDT.java

License:Open Source License

/**
 * Converts a DateTimeObject into a string with format DD/MM/YYYY
 *
 * @param dt a DateTime object/*ww w  .  j av  a2 s  .co  m*/
 * @return the formatted String or null
 */
public static String formatDDMMYYYY(DateTime dt) {
    if (dt != null) {
        DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
        dtfb.appendDayOfMonth(2);
        dtfb.appendLiteral('/');
        dtfb.appendMonthOfYear(2);
        dtfb.appendLiteral('/');
        dtfb.appendYear(4, 4);
        DateTimeFormatter dtf = dtfb.toFormatter();
        String str = dt.toString(dtf);
        return str;
    } else {
        return null;
    }
}

From source file:au.org.scoutmaster.domain.Contact.java

public void setBirthDate(final String fieldValue) {
    final DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
            DateTimeFormat.forPattern("yyyy/MM/dd").getParser() };
    final DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();

    if (fieldValue != null && fieldValue.length() > 0) {
        final DateTime date1 = formatter.parseDateTime(fieldValue);
        setBirthDate(new java.sql.Date(date1.toDate().getTime()));
    }/*from   www.  j  a va2s.  com*/
}

From source file:ca.phon.app.session.editor.actions.BackupCommandHook.java

License:Open Source License

private void backupSession(Project project, Session session) throws IOException, ZipException {
    // save current session to backup zip
    final String zipFilePath = project.getLocation() + File.separator + "backups.zip";
    // create backup zip if necessary
    final ZipFile zipFile = new ZipFile(zipFilePath);

    final DateTime dateTime = DateTime.now();
    final DateTimeFormatterBuilder formatterBuilder = new DateTimeFormatterBuilder();
    final String dateSuffix = formatterBuilder.appendYear(4, 4).appendLiteral("-").appendMonthOfYear(2)
            .appendLiteral("-").appendDayOfMonth(2).appendLiteral("_").appendHourOfDay(2).appendLiteral(".")
            .appendMinuteOfHour(2).appendLiteral(".").appendSecondOfMinute(2).toFormatter().print(dateTime);

    final String zipName = session.getName() + "_" + dateSuffix + ".xml";

    final File sessionFile = new File(project.getLocation(),
            session.getCorpus() + File.separator + session.getName() + ".xml");

    if (sessionFile.exists()) {
        if (!zipFile.getFile().exists()) {
            ZipParameters parameters = new ZipParameters();

            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

            zipFile.createZipFile(new File(project.getLocation() + File.separator + "project.xml"), parameters);
        }//from   w  w  w .  j  av a 2 s  . c o m
        // add to zip file
        ZipParameters parameters = new ZipParameters();
        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

        parameters.setFileNameInZip(session.getCorpus() + File.separator + zipName);
        parameters.setSourceExternalStream(true);

        FileInputStream fin = null;
        try {
            fin = new FileInputStream(sessionFile);
            zipFile.addStream(fin, parameters);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);

        } finally {
            if (fin != null)
                fin.close();
        }
    }
}