/** * Creates a format tracking wrapper around the given listener, using * the {@link Locale#getDefault() default locale} for the formats. * * @param childListener the listener to be wrapped */ public FormatTrackingHSSFListener(HSSFListener childListener) { this(childListener, LocaleUtil.getUserLocale()); }
/** * Convenience method - month is 0-based as in java.util.Calendar * * @param year * @param month * @param day * @return a calendar for the user locale and time zone, and the given date */ public static Calendar getLocaleCalendar(int year, int month, int day) { return getLocaleCalendar(year, month, day, 0, 0, 0); }
/** * @return a calendar for the user locale and time zone */ public static Calendar getLocaleCalendar() { return getLocaleCalendar(getUserTimeZone()); }
SimpleDateFormat df = null; if (dateFormat != null) { df = new SimpleDateFormat(dateFormat, LocaleUtil.getUserLocale()); df.setTimeZone(LocaleUtil.getUserTimeZone());
private String getFormattedDate(XSSFCell cell) { DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); return sdf.format(cell.getDateCellValue()); }
TimeZone currentTimeZone = LocaleUtil.getUserTimeZone(); try { LocaleUtil.setUserTimeZone(timeZone); cell.setCellValue(date); } finally { if (Objects.equals(currentTimeZone, TimeZone.getDefault())) { LocaleUtil.resetUserTimeZone(); } else { LocaleUtil.setUserTimeZone(currentTimeZone);
setUserTimeZone(LocaleUtil.TIMEZONE_UTC); Date dateCellValue = cell.getDateCellValue(); value = formatUTCDateAsLocalDateTime(dateCellValue); } finally { resetUserTimeZone();
private String decodeValueFromID() { try { switch((int)getID()) { case PropertyIDMap.PID_CODEPAGE: return CodePageUtil.codepageToEncoding(((Number)value).intValue()); case PropertyIDMap.PID_LOCALE: return LocaleUtil.getLocaleFromLCID(((Number)value).intValue()); } } catch (Exception e) { LOG.log(POILogger.WARN, "Can't decode id "+getID()); } return null; }
case NUMERIC: if (DateUtil.isCellDateFormatted(this)) { DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale()); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); return sdf.format(getDateCellValue());
/** * Creates a new date formatter with the given specification. * * @param locale The locale. * @param format The format. */ public CellDateFormatter(Locale locale, String format) { super(format); DatePartHandler partHandler = new DatePartHandler(); StringBuffer descBuf = CellFormatPart.parseFormat(format, CellFormatType.DATE, partHandler); partHandler.finish(descBuf); // tweak the format pattern to pass tests on JDK 1.7, // See https://issues.apache.org/bugzilla/show_bug.cgi?id=53369 String ptrn = descBuf.toString().replaceAll("((y)(?!y))(?<!yy)", "yy"); dateFmt = new SimpleDateFormat(ptrn, locale); dateFmt.setTimeZone(LocaleUtil.getUserTimeZone()); }
private String decodeValueFromID() { try { switch((int)getID()) { case PropertyIDMap.PID_CODEPAGE: return CodePageUtil.codepageToEncoding(((Number)value).intValue()); case PropertyIDMap.PID_LOCALE: return LocaleUtil.getLocaleFromLCID(((Number)value).intValue()); } } catch (Exception e) { LOG.log(POILogger.WARN, "Can't decode id "+getID()); } return null; }
/** * Creates a formatter using the {@link Locale#getDefault() default locale}. */ public HSSFDataFormatter() { this(LocaleUtil.getUserLocale()); }
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale()); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); return sdf.format(getDateCellValue());
/** * Convenience method - month is 0-based as in java.util.Calendar * * @param year * @param month * @param day * @param hour * @param minute * @param second * @return a calendar for the user locale and time zone, and the given date */ public static Calendar getLocaleCalendar(int year, int month, int day, int hour, int minute, int second) { Calendar cal = getLocaleCalendar(); cal.set(year, month, day, hour, minute, second); cal.clear(Calendar.MILLISECOND); return cal; }
/** * @return a calendar for the user locale and time zone */ public static Calendar getLocaleCalendar() { return getLocaleCalendar(getUserTimeZone()); }
defaultDateformat.setTimeZone(LocaleUtil.getUserTimeZone());
/** * Creates a new cell number formatter. * * @param format The format to parse. */ public CellNumberFormatter(String format) { this(LocaleUtil.getUserLocale(), format); }
case NUMERIC: if (DateUtil.isCellDateFormatted(this)) { DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale()); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); return sdf.format(getDateCellValue());
private static Calendar getDate(double date) { Calendar processedDate = LocaleUtil.getLocaleCalendar(); processedDate.setTime(DateUtil.getJavaDate(date, false)); return processedDate; }
private String getFormattedDate(XSSFCell cell) { DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); return sdf.format(cell.getDateCellValue()); }