• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

DateFormat

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and welcome to javaranch tp knotts
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic