• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DateFormat

 
tp knotts
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help please!
According to ISO, http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm, Jan 26th should be week 4 of 2010 for DateFormat ww.
However, when I run the following, I get week 5:

String myStrDate = "01/26/2010";
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date myDate = df.parse(myStrDate);
String weekday = new SimpleDateFormat("EEE").format(myDate);
String ww = new SimpleDateFormat("ww").format(myDate);
System.out.print(myDate + "\n" + weekday + "\n" + ww);
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Number of week in a year depends on your locale.
Run this code:

and you'll get week 4 or 5 for different locales:

Tue Jan 26 00:00:00 CET 2010 # 05 # ja_JP
Tue Jan 26 00:00:00 CET 2010 # 05 # es_PE
Tue Jan 26 00:00:00 CET 2010 # 05 # en
Mon Jan 26 00:00:00 CET 3998 # 05 # ja_JP_JP
Tue Jan 26 00:00:00 CET 2010 # 05 # es_PA
Tue Jan 26 00:00:00 CET 2010 # 05 # sr_BA
Tue Jan 26 00:00:00 CET 2010 # 05 # mk
..................................
...................................
Tue Jan 26 00:00:00 CET 2010 # 04 # el
Tue Jan 26 00:00:00 CET 2010 # 05 # ms
Tue Jan 26 00:00:00 CET 2010 # 04 # sv_SE
Tue Jan 26 00:00:00 CET 2010 # 04 # da_DK
Tue Jan 26 00:00:00 CET 2010 # 05 # es_HN
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the WEEK_OF_YEAR is defined in the API for the GregorianCalendar
Values calculated for the WEEK_OF_YEAR field range from 1 to 53. Week 1 for a year is the earliest seven day period starting on getFirstDayOfWeek() that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java classes DateFormat and SimpleDateFormat do not implement the ISO 8601 standard, they have their own rules as Larry quoted. So there's no reason to expect that it will behave the way the ISO 8601 standard specifies.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and welcome to javaranch tp knotts
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic