Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

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

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.axelor.i18n.L10n.java

License:Open Source License

/**
 * Format the date value.//from  w  ww.  jav  a  2s .  c  om
 *
 * @param value
 *            the value to format
 * @return value as formated string
 */
public String format(LocalDate value) {
    if (value == null) {
        return null;
    }
    return DateTimeFormat.forPattern(DATE_FORMAT).print(value);
}

From source file:com.axelor.i18n.L10n.java

License:Open Source License

/**
 * Format the date time value./* w ww .j a v  a  2  s.c  o  m*/
 *
 * @param value
 *            the value to format
 * @return value as formated string
 */
public String format(LocalDateTime value) {
    if (value == null) {
        return null;
    }
    return DateTimeFormat.forPattern(DATE_TIME_FORMAT).print(value);
}

From source file:com.axelor.i18n.L10n.java

License:Open Source License

/**
 * Format the date time value./*from  w  ww.j  a  va  2s.  c om*/
 *
 * @param value
 *            the value to format
 * @return value as formated string
 */
public String format(DateTime value) {
    if (value == null) {
        return null;
    }
    return DateTimeFormat.forPattern(DATE_TIME_FORMAT).print(value);
}

From source file:com.baidubce.services.lss.LssClient.java

License:Open Source License

/**
 * Get your live session with token by live session id.
 *
 * @param sessionId  Live session id./* w ww  . jav  a 2 s .co m*/
 * @param timeoutInMinute  Timeout of token.
 *
 * @return Your live session with token.
 */
public GetSessionResponse getSessionWithToken(String sessionId, Integer timeoutInMinute) {
    GetSessionResponse getSessionResponse = getSession(sessionId);
    if (timeoutInMinute == null) {
        return getSessionResponse;
    }
    DateTime dateTime = new DateTime(DateTimeZone.UTC);
    DateTime expireTime = dateTime.plusMinutes(timeoutInMinute);
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
    String expire = formatter.print(expireTime);

    GetSecurityPolicyResponse getSecurityPolicyResponse = getSecurityPolicy(
            getSessionResponse.getSecurityPolicy());
    if (getSecurityPolicyResponse.getAuth().getPlay()) {
        String hlsUrl = getSessionResponse.getPlay().getHlsUrl();
        String rtmpUrl = getSessionResponse.getPlay().getRtmpUrl();
        if (hlsUrl != null) {
            String hlsToken = LssUtils.hmacSha256(String.format("/%s/live.m3u8;%s", sessionId, expire),
                    getSecurityPolicyResponse.getAuth().getKey());
            if (hlsUrl.lastIndexOf('?') == -1) {
                hlsUrl += String.format("?token=%s&expire=%s", hlsToken, expire);
            } else {
                hlsUrl += String.format("&token=%s&expire=%s", hlsToken, expire);
            }
            getSessionResponse.getPlay().setHlsUrl(hlsUrl);
        }
        if (rtmpUrl != null) {
            String rtmpToken = LssUtils.hmacSha256(String.format("%s;%s", sessionId, expire),
                    getSecurityPolicyResponse.getAuth().getKey());
            rtmpUrl += String.format("?token=%s&expire=%s", rtmpToken, expire);
            getSessionResponse.getPlay().setRtmpUrl(rtmpUrl);
        }
    }

    if (getSecurityPolicyResponse.getAuth().getPush()) {
        String pushUrl = getSessionResponse.getPublish().getPushUrl();
        String pushToken = LssUtils.hmacSha256(
                String.format("%s;%s", getSessionResponse.getPublish().getPushStream(), expire),
                getSecurityPolicyResponse.getAuth().getKey());
        pushUrl += String.format("?token=%s&expire=%s", pushToken, expire);
        getSessionResponse.getPublish().setPushUrl(pushUrl);
    }
    return getSessionResponse;
}

From source file:com.bancandes.dao.Consultas.java

public static DateTime getCurrentDate() {
    DateTime date = null;/*from www .java 2  s .c om*/
    try {
        Conexion conn = new Conexion();
        String sentencia = "SELECT TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS') \"NOW\" FROM DUAL";
        PreparedStatement ps = conn.getConexion().prepareStatement(sentencia);
        ResultSet rs = ps.executeQuery();
        rs.next();
        String now = rs.getString(1);
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd H:mm:ss");
        date = formatter.parseDateTime(now);

    } catch (SQLException ex) {
        Logger.getLogger(Consultas.class.getName()).log(Level.SEVERE, null, ex);

    }
    return date;
}

From source file:com.bancandes.dao.Consultas.java

public static String formatDate(DateTime dt) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/mm/dd HH:mm:ss");
    return dtf.print(dt);
}

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.bancvue.mongomigrate.CreateCommand.java

License:Apache License

private String generateMigrationFileName(String userProvidedName) {
    String dateTimePrefix = DateTimeFormat.forPattern("yyyyMMddHHmmss").print(clock.getCurrentDateTime());
    String namePostFix = StringUtils.isNotEmpty(userProvidedName) ? userProvidedName : "migration";
    return dateTimePrefix + "_" + namePostFix + ".js";
}

From source file:com.baulsupp.kolja.log.line.type.DateType.java

License:Open Source License

public DateTime parse(String string) {
    if (dateFormat == null) {
        this.dateFormat = DateTimeFormat.forPattern(pattern);
    }//from w  w w . j  ava 2 s. co m

    if (string == null) {
        return null;
    }

    try {
        return dateFormat.parseDateTime(string);
    } catch (IllegalArgumentException e) {
        log.error("error parsing date", e);

        return null;
    }
}

From source file:com.baulsupp.kolja.log.viewer.format.JodaFormat.java

License:Open Source License

public String format(Object value) {
    if (value == null) {
        return null;
    }/*from w  ww  .  ja  v  a 2s  .c  o  m*/

    if (formatter == null) {
        formatter = DateTimeFormat.forPattern(pattern);
    }

    return formatter.print((DateTime) value);
}