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.bancandes.dao.Consultas.java

public static String toDate(DateTime dt) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");
    String fecha = dtf.print(dt);
    return "TO_DATE('" + fecha + "', 'yyyy/mm/dd hh24:mi:ss' )";
}

From source file:com.bitlove.fetlife.util.DateUtil.java

License:Apache License

public static String toServerString(long time) {

    //2017-01-24 16:52:33.074 +0200'

    DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral('-')
            .appendMonthOfYear(2).appendLiteral('-').appendDayOfMonth(2).appendLiteral(' ').appendHourOfDay(2)
            .appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':').appendSecondOfMinute(2)
            .appendLiteral('.').appendMillisOfSecond(3).appendLiteral(' ')
            .appendTimeZoneOffset(null, false, 2, 2).toFormatter();

    return dateTimeFormatter.print(time);
}

From source file:com.bluexml.side.clazz.generator.alfresco.api.service.ValueGenerator.java

License:Open Source License

public String getPropertyTestValue(Attribute node, String seedS) throws Exception {
    if (node.getValueList() != null) {
        EnumerationLiteral enumerationLiteral = node.getValueList().getLiterals().get(0);
        if (enumerationLiteral.getValue() == null || enumerationLiteral.getValue().equals("")) {
            return enumerationLiteral.getName();
        }//ww  w .j a v a2  s . c  om
        return enumerationLiteral.getValue();
    } else {
        int seed;
        if (!seedS.equals("")) {
            seed = Integer.parseInt(seedS);
        } else {
            seed = 0;
        }

        DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
        Date date = null;
        Calendar c = Calendar.getInstance();
        c.set(1978 + seed, 11, 22, 13, 30, 0);
        date = c.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        String dateString = sdf.format(date);
        dateString = dateTimeFormatter.print(date.getTime());
        Boolean bool = seed % 2 == 0;
        Integer integer = 5 + seed;
        String str = "text" + seedS;
        Double db = 5.65699245 + seed;
        Float fl = 2.345F + seed;
        Long lg = 634554345345L + seed;

        if (node instanceof Attribute) {
            Attribute object = (Attribute) node;
            if (object.getTyp() == DataType.BOOLEAN) {
                return bool.toString();
            } else if (object.getTyp() == DataType.BYTE) {
                return integer.toString();
            } else if (object.getTyp() == DataType.CHAR) {
                return str;
            } else if (object.getTyp() == DataType.DATE) {
                return dateString;
            } else if (object.getTyp() == DataType.DATE_TIME) {
                return dateString;
            } else if (object.getTyp() == DataType.DOUBLE) {
                return db.toString();
            } else if (object.getTyp() == DataType.FLOAT) {
                return fl.toString();
            } else if (object.getTyp() == DataType.INT) {
                return integer.toString();
            } else if (object.getTyp() == DataType.LONG) {
                return lg.toString();
            } else if (object.getTyp() == DataType.OBJECT) {
                // return "d:content";
                return "";
            } else if (object.getTyp() == DataType.SHORT) {
                return integer.toString();
            } else if (object.getTyp() == DataType.STRING) {
                return str;
            } else if (object.getTyp() == DataType.TIME) {
                return dateString;
            }
        }
    }
    throw new Exception("node must be an attribute");
}

From source file:com.code2040.bofashola.DatingGame.java

private static String getISO(String dateStamp, long seconds) {
    String str = "";

    //parse the datestamp string
    String date = dateStamp.split("T")[0];
    String time = dateStamp.split("T")[1];
    int year = Integer.valueOf(date.split("-")[0]);
    int month = Integer.valueOf(date.split("-")[1]);
    int dat = Integer.valueOf(date.split("-")[2]);
    int hrs = Integer.valueOf(time.split(":")[0]);
    int minute = Integer.valueOf(time.split(":")[1]);
    String secTemp = (time.split(":")[2]);
    int sec = Integer.valueOf(secTemp.charAt(0) + "" + secTemp.charAt(1));
    DateTime dt = new DateTime(year, month, dat, hrs, minute, sec);
    //Convert the string to milliseconds and add the interval in milliseconds
    long timeInMills = dt.getMillis() + getMilliseconds(seconds);
    DateTime newtime = new DateTime(timeInMills);
    //Use the Joda Time API and change it to ISO 8061 format
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    str = fmt.print(newtime);
    return str.replace(str.substring(23, str.length()), "Z");
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Gets the calendar./*  w  w w . jav a  2s.c o  m*/
 * 
 * @param startTime the start time
 * @param minutes the minutes
 * @param pattern the pattern
 * @return the calendar
 */
public static Calendar getCalendar(Calendar startTime, int minutes, final String pattern) {

    Calendar endTime = null;
    DateTime start = new DateTime(startTime);
    DateTime end = start.plusMinutes(minutes);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    endTime = parseToUTCCalendar(fmt.print(end), pattern);
    return endTime;
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Gets the UTC current time stamp./*w ww .j  av  a 2 s .  c o  m*/
 * 
 * @param pattern the pattern
 * @return the UTC current time stamp
 */
public static String getUTCCurrentTimeStamp(String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    return fmt.print(new DateTime(DateTimeZone.UTC));
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Gets the current time stamp for zone.
 * /*from   ww w .  ja  v a2s  .c  om*/
 * @param timeZone the time zone
 * @param pattern the pattern
 * @return the current time stamp for zone
 */
public static String getCurrentTimeStampForZone(String timeZone, String pattern) {

    DateTime startDate = new DateTime(DateTimeZone.forID(timeZone));
    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    return fmt.print(startDate);
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Format./*from  w  ww . ja  va 2  s.c o m*/
 * 
 * @param calendar the calendar
 * @param pattern the pattern
 * @return the string
 */
public static String format(Calendar calendar, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    return fmt.print(new DateTime(calendar));
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Format to utc./*from w  w  w . ja va2  s.co m*/
 * 
 * @param calendar the calendar
 * @param pattern the pattern
 * @return the string
 */
public static String formatToUTC(Calendar calendar, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    String strDate = fmt.print(new DateTime(calendar));
    return strDate;
}

From source file:com.coderoad.automation.common.util.DateUtil.java

License:Open Source License

/**
 * Format to utc./*from  www. ja  va2  s.c o m*/
 * 
 * @param date the date
 * @param pattern the pattern
 * @return the string
 */
public static String formatToUTC(Date date, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    String strDate = fmt.print(new DateTime(date));
    return strDate;
}