Name: jl125535 Date: 01/12/2004
A DESCRIPTION OF THE REQUEST :
It would be usefull if SimpleDateFormat could print
(DAY_OF_WEEK-firstDayOfWeek+1) as a digit, since now
DAY_OF_WEEK can only be printed as a locale specific string.
This is an issue specifically in the case where I wish to
print ISO 8601 week specified dates (see
ftp://ftp.qsl.net/pub/g1smd/8601v03.pdf)
Name: Date pattern String: Value:
Calendar date: "yyyy-MM-dd" 2001-05-02
Ordinal date: "yyyy-DDD" 2001-122
Week spec date: "yyyy-'W'ww-??" 2001-W18-3
SimpleDateFormat has no pattern letter for this value, so
can not display, or parse week specified dates. Once
implemented, also consider adding factory methods to DateFormat:
DateFormat.getISODateInstance()
DateFormat.getISOOrdinalInstance()
DateFormat.getISOWeekInstance()
Currently the pattern letter 'E' is implemented to be
DAY_OF_WEEK (as a String), and I think 'e' would be an
excellent candidate for DAY_OF_WEEK as a digit. Like
WEEK_IN_YEAR, which relies upon
'Calendar.getMinimalDaysInFirstWeek()' the DAY_OF_WEEK as a
digit would rely upon 'Calendar.getFirstDayOfWeek()', with
firstDayOfWeek being '1'.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER WORKAROUND :
1) to print:
Calendar calendar...
Date date....
SimpleDateFormat weekF = new SimpleDateFormat("yyyy-'W'ww-");
weekF.setCalendar(calendar);
calendar.setTime(date);
int dayOfWeek = ((calendar.get(Calendar.DAY_OF_WEEK) -
calendar.getFirstDayOfWeek() +7) %7) +1;
System.out.println(weekF.format(date)+dayOfWeek);
2) to parse:
I haven't had to but it will involve your own
StringTokenizer, calendar.get(Calendar.DAY_OF_WEEK),
calendar.getFirstDayOfWeek(), and some arithmetic.
(Incident Review ID: 180264)
======================================================================
- relates to
-
JDK-4267450 (cal) API: Need public API to calculate, format and parse "year of week"
- Closed