Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.poi.ss.util
Class DateFormatConverter

    java.lang.Object
      org.apache.poi.ss.util.DateFormatConverter

    public class DateFormatConverter

extends java.lang.Object

Convert java DateFormat patterns into Excel custom number formats. For example, to format a date in excel using the "dd MMMM, yyyy" pattern and Japanese locale, use the following code:

          // returns "[$-0411]dd MMMM, yyyy;@" where the [$-0411] prefix tells Excel to use the Japanese locale
          String excelFormatPattern = DateFormatConverter.convert(Locale.JAPANESE, "dd MMMM, yyyy");

          CellStyle cellStyle = workbook.createCellStyle();

          DataFormat poiFormat = workbook.createDataFormat();
          cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
          cell.setCellValue(new Date());
          cell.setCellStyle(cellStyle);  // formats date as '2012年3月17日'

TODO Generalise this for all Excel format strings

Nested Class Summary
`static class` | `DateFormatConverter.DateFormatTokenizer`

Constructor Summary
`DateFormatConverter()`

Method Summary
`static java.lang.String` | `convert(java.util.Locale locale, java.text.DateFormat df)`
`static java.lang.String` | `convert(java.util.Locale locale, java.lang.String format)`
`static java.lang.String` | `getJavaDatePattern(int style, java.util.Locale locale)`
`static java.lang.String` | `getJavaDateTimePattern(int style, java.util.Locale locale)`
`static java.lang.String` | `getJavaTimePattern(int style, java.util.Locale locale)`
`static java.lang.String` | `getPrefixForLocale(java.util.Locale locale)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DateFormatConverter

    public DateFormatConverter()

Method Detail

### getPrefixForLocale

    public static java.lang.String getPrefixForLocale(java.util.Locale locale)

### convert

    public static java.lang.String convert(java.util.Locale locale,
                                           java.text.DateFormat df)

### convert

    public static java.lang.String convert(java.util.Locale locale,
                                           java.lang.String format)

### getJavaDatePattern

    public static java.lang.String getJavaDatePattern(int style,
                                                      java.util.Locale locale)

### getJavaTimePattern

    public static java.lang.String getJavaTimePattern(int style,
                                                      java.util.Locale locale)

### getJavaDateTimePattern

    public static java.lang.String getJavaDateTimePattern(int style,
                                                          java.util.Locale locale)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2017 The Apache Software Foundation or its licensors, as applicable.