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

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

Introduction

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

Prototype

public DateTimeFormatterBuilder appendYear(int minDigits, int maxDigits) 

Source Link

Document

Instructs the printer to emit a numeric year field.

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.//w  w w  . ja va  2s  . c  om
 *
 * @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./*w  w  w  . j  a va2s.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 av  a  2  s  . c o m
 */
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//from  w w w .j a  v a 2  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  av 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/*from  ww  w .  ja v  a 2 s.  c o m*/
 * @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//w w  w.ja  va2s  . c  om
 * @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/*from   w  ww  . j  ava2  s .com*/
 * @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: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 ww  . 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();
        }
    }
}

From source file:ch.eitchnet.android.util.JodaHelper.java

License:Open Source License

/**
 * @param timestamp//from   www .  ja  v  a 2 s .  c o m
 * @return
 */
public static String toDateHourMinute(ReadablePartial timestamp) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder.appendYear(4, 4).appendLiteral("-").appendMonthOfYear(2).appendLiteral("-").appendDayOfMonth(2);
    builder.appendLiteral(" ").appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2);
    return builder.toFormatter().print(timestamp);
}