jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Showing Only Date Instead of time #249

Open AhmedAli1050 opened 8 months ago

AhmedAli1050 commented 8 months ago

Still getting the same issue, showing date with time like 01/14/2024 09:00:00/ 01/01/2018 09:00:00 and how can we show only date instead of time

cal.set(2017, 12, 1, 0, 0, 0); walker.setDateValue(cal); // Add a custom format final DataStyle dateStyle = new DateStyleBuilder("custom-date-datastyle", Locale.US) .dateFormat( new DateTimeStyleFormat(DateTimeStyleFormat.DAY, DateTimeStyleFormat.DOT, DateTimeStyleFormat.MONTH, DateTimeStyleFormat.DOT, DateTimeStyleFormat.YEAR)).visible().build(); walker.setDataStyle(dateStyle); walker.next();

jferard commented 7 months ago

Hello, Sorry for the (very) late answer. The display is correct (only year - month - day), but the value has hours. You get the hours because of the timezone of the calendar instance and because of the milliseconds. I added some hint in the doc and examples (see : https://github.com/jferard/fastods/commit/e570f44d3ab6c76fa6b231bd261453213ea46542). Here is the relevant part:

        // A date with the standard format.
        // Warning : you probably want to set milliseconds to 0 and use correct time zone
        final Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(2018, Calendar.FEBRUARY, 1, 0, 0, 0);

This removes the hours for the date value.