Search in sources :

Example 36 with DateFormat

use of java.text.DateFormat in project Honu by jboulon.

the class ISO8601 method getTime.

/**
	 * Date in ISO8601 format:
	 * yyyy-MM-dd'T'HH:mm:ss,SSS
	 * @param dateStr
	 * @return
	 * @throws ParseException 
	 */
public static long getTime(String dateStr) throws ParseException {
    synchronized (calendar) {
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        DateFormat outdfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SSS");
        outdfm.setTimeZone(TimeZone.getTimeZone("GMT"));
        calendar.setTime(outdfm.parse(dateStr));
        return calendar.getTimeInMillis();
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 37 with DateFormat

use of java.text.DateFormat in project Openfire by igniterealtime.

the class StatsAction method formatTimeLong.

/**
     * Formats a given time using the <code>DateFormat.MEDIUM</code>. In the 'en' locale, this
     * should result in a time formatted like this: 4:59:23 PM. The seconds are necessary when
     * displaying time in the conversation scroller.
     * @param time
     * @return string a date formatted using DateFormat.MEDIUM
     */
public static String formatTimeLong(Date time) {
    DateFormat formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, JiveGlobals.getLocale());
    formatter.setTimeZone(JiveGlobals.getTimeZone());
    return formatter.format(time);
}
Also used : DateFormat(java.text.DateFormat)

Example 38 with DateFormat

use of java.text.DateFormat in project hs4j by killme2008.

the class ResultSetImpl method getDateFromString.

private Date getDateFromString(String stringVal, Calendar cal) throws SQLException {
    if (stringVal == null) {
        this.lastWasNull = true;
        return null;
    }
    String val = stringVal.trim();
    if (val.length() == 0) {
        this.lastWasNull = true;
        return null;
    }
    if (val.equals("0") || val.equals("0000-00-00") || val.equals("0000-00-00 00:00:00") || val.equals("00000000000000") || val.equals("0")) {
        Calendar calendar = null;
        if (cal != null) {
            calendar = Calendar.getInstance(cal.getTimeZone());
        } else {
            calendar = Calendar.getInstance();
        }
        calendar.set(Calendar.YEAR, 1);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return new Date(calendar.getTimeInMillis());
    }
    DateFormat dateFormat = DateFormat.getDateTimeInstance();
    if (cal != null) {
        TimeZone timeZone = cal.getTimeZone();
        dateFormat.setTimeZone(timeZone);
    }
    try {
        return new Date(dateFormat.parse(val).getTime());
    } catch (ParseException e) {
        throw new SQLException("Parse date failure:" + val);
    }
}
Also used : TimeZone(java.util.TimeZone) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Date(java.sql.Date)

Example 39 with DateFormat

use of java.text.DateFormat in project head by mifos.

the class DateTag method getUserFormat.

String getUserFormat(Locale locale) {
    // the following line will be removed when date is localized
    locale = Locale.UK;
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    return ((SimpleDateFormat) df).toPattern();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 40 with DateFormat

use of java.text.DateFormat in project head by mifos.

the class LocalizationConverter method getDateSeparator.

public String getDateSeparator(Locale locale, int dateFormat) {
    String separator = "";
    DateFormat format = DateFormat.getDateInstance(dateFormat, locale);
    String now = format.format(new DateTimeService().getCurrentJavaDateTime());
    char[] chArray = now.toCharArray();
    for (char element : chArray) {
        if (Character.isDigit(element) == false) {
            separator = String.valueOf(element);
            break;
        }
    }
    return separator;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8