Example usage for java.text SimpleDateFormat applyLocalizedPattern

List of usage examples for java.text SimpleDateFormat applyLocalizedPattern

Introduction

In this page you can find the example usage for java.text SimpleDateFormat applyLocalizedPattern.

Prototype

public void applyLocalizedPattern(String pattern) 

Source Link

Document

Applies the given localized pattern string to this date format.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    SimpleDateFormat formatter = new SimpleDateFormat();
    formatter.applyLocalizedPattern("MMM");
    String s = formatter.format(new Date());
    System.out.println(s);//from w  w  w .jav a 2 s  . c  o m
}

From source file:Main.java

public static String formatLocale(Date date, String format) {
    String result = "";
    if (date != null) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        dateFormat.applyLocalizedPattern(format);

        try {/*from  w ww.  j  av a 2  s  .  c o m*/
            result = dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return result;
        }
    }
    return result;
}

From source file:Main.java

public static String formatTimestamp(Context context, long timestamp) {
    String HOURS_24 = "24";
    String hours;//  ww  w .  j a v  a  2s  .com
    hours = Settings.System.getString(context.getContentResolver(), Settings.System.TIME_12_24);

    SimpleDateFormat mSDF = new SimpleDateFormat();
    if (HOURS_24.equals(hours)) {
        mSDF.applyLocalizedPattern(TIME_FORMAT_24_HOUR);
    } else {
        mSDF.applyLocalizedPattern(TIME_FORMAT_12_HOUR);
    }
    return mSDF.format(new Date(timestamp));
}

From source file:org.addhen.smssync.util.Util.java

/**
 * Format an Unix timestamp to a string suitable for display to the user
 * according to their system settings (12 or 24 hour time).
 * //from w  w  w.j  a v a  2 s .c o m
 * @param Context
 *            context - The context of the calling activity.
 * @param long timestamp - The human unfriendly timestamp.
 * @return String
 */
public static String formatTimestamp(Context context, long timestamp) {
    String HOURS_24 = "24";
    String hours = "24";

    SimpleDateFormat mSDF = new SimpleDateFormat();
    if (HOURS_24.equals(hours)) {
        mSDF.applyLocalizedPattern(TIME_FORMAT_24_HOUR);
    } else {
        mSDF.applyLocalizedPattern(TIME_FORMAT_12_HOUR);
    }
    return mSDF.format(new Date(timestamp));
}

From source file:com.fantasy.stataggregator.workers.StatCompilerTask.java

@Override
public void setYear(int year) throws Exception {
    this.year = year;

    GameDataRepository gdr = ctx.getBean(GameDataRepository.class);
    if (year == Integer.MAX_VALUE) {
        gamesData = gdr.findAll();/*  ww w. j a  v  a  2  s .  c o  m*/
    } else {
        SimpleDateFormat sdf = ctx.getBean(SimpleDateFormat.class);
        sdf.applyLocalizedPattern("yyyyMMdd");

        Date min = sdf.parse(year + START_OF_YEAR);
        Date max = sdf.parse(year + END_OF_YEAR);

        CriteriaBuilder cb = gdr.getCriteriaBuilder();
        CriteriaQuery<GameData> cq = gdr.getCriteriaQuery();
        Root<GameData> gameData = gdr.getRoot();
        Path<GameDataPK> pk = gameData.get(GameData_.gameDataPK);
        cq.select(gameData).where(cb.equal(pk.get(GameDataPK_.year), year))
                .orderBy(cb.asc(pk.get(GameDataPK_.gameIdentifier)));

        gamesData = gdr.getCriteriaList(cq);
        System.out.println(gamesData.size());
    }
}

From source file:nz.net.orcon.kanban.automation.AutomationEngineTestIT.java

@Test
public void testEvalProperty_time() {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.applyLocalizedPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");

    Date date = new Date();

    String time1 = "xs:dateTime('" + df.format(date) + "+00:00')";
    System.out.println(time1);/*from   w w w . j  a v  a  2  s .c  o  m*/
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    String time = "xs:dateTime('" + df.format(date) + "+00:00')";
    System.out.println(time);
}

From source file:net.sf.jasperreports.engine.util.JRDateLocaleConverter.java

@Override
protected Object parse(Object value, String pattern) throws ParseException {
    SimpleDateFormat formatter = getFormatter(pattern, locale);
    if (pattern != null) {
        if (locPattern) {
            formatter.applyLocalizedPattern(pattern);
        } else {/*from www. ja va2s  .co m*/
            formatter.applyPattern(pattern);
        }
    }
    return formatter.parse((String) value);
}

From source file:com.fantasy.stataggregator.workers.GameDataRetrieverTask.java

/**
 * Sets the statistical year to be requested.
 *
 * @param year/*from w  w w .  jav a  2s  .c  o  m*/
 * @throws java.text.ParseException
 */
@Override
public void setYear(int year) throws ParseException {
    if (Objects.nonNull(ctx)) {
        this.year = year;
        isTaskComplete = false;
        GameScheduleRepository gsr = ctx.getBean(GameScheduleRepository.class);
        if (year == Integer.MAX_VALUE) {
            schedules = gsr.findAll();
        } else {
            SimpleDateFormat sdf = ctx.getBean(SimpleDateFormat.class);
            sdf.applyLocalizedPattern("yyyyMMdd");

            Date min = sdf.parse(year + START_OF_YEAR);
            Date max = sdf.parse(year + END_OF_YEAR);

            CriteriaBuilder cb = gsr.getCriteriaBuilder();
            CriteriaQuery<GameSchedule> cq = gsr.getCriteriaQuery();
            Root<GameSchedule> gameSchedule = gsr.getRoot();
            cq.select(gameSchedule).where(cb.between(gameSchedule.get(GameSchedule_.gamedate), min, max))
                    .orderBy(cb.asc(gameSchedule.get(GameSchedule_.gameid)));

            schedules = gsr.getCriteriaList(cq);
            System.out.println(schedules.size());
        }
    }
}

From source file:org.enerj.apache.commons.beanutils.locale.converters.DateLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type./*from  ww  w  .ja  v  a2  s . c o m*/
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 *
 * @exception org.enerj.apache.commons.beanutils.ConversionException if conversion cannot be performed
 *  successfully
 */
protected Object parse(Object value, String pattern) throws ParseException {
    SimpleDateFormat formatter = getFormatter(pattern, locale);
    if (locPattern) {
        formatter.applyLocalizedPattern(pattern);
    } else {
        formatter.applyPattern(pattern);
    }
    return formatter.parse((String) value);
}

From source file:nz.net.orcon.kanban.tools.ListTools.java

private SimpleDateFormat createSimpleDateFormat() {
    // xs:dateTime('2008-01-01T00:00:00.000+02:00')
    // yyyy-MM-dd'T'HH:mm:ss.SSSXXX
    final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    df.applyLocalizedPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
    return df;/*from w ww. j a v a  2  s . c  o m*/
}