Date question

Hello all

anyone know of a easy way to work with this date senario:
I have the year in the format of 2004. (any year,including leap years)
i have the day in the format of 111. (any date 1-366)

I need to find out what day this is? (ie 2004, 27 would give me January 27 2004)
thanks

LVL 4
91mustangAsked:
Who is Participating?
 
CEHJCommented:
Assuming you've got Strings as input (remove Integer.parseInt if not) this will give you your required format:


   SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy");
   Calendar c = Calendar.getInstance();
   c.set(Calendar.YEAR, Integer.parseInt("2004"));
   c.set(Calendar.DAY_OF_YEAR, Integer.parseInt("111"));
   System.out.println(sdf.format(c.getTime()));
0
 
CEHJCommented:
Use a Calendar and set the appropriate fields
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Nick_72Commented:
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, 2004);
    c.set(Calendar.DAY_OF_YEAR, 27);
    System.out.println(sdf.format(c.getTime()));
0
 
91mustangAuthor Commented:
thanks :)
0
 
CEHJCommented:
8-)
0
 
Nick_72Commented:
You're welcome
0
 
91mustangAuthor Commented:
Sorry nick, I was in a rush when i looked at the anwer, and didn't notice someone other than CEHJ posted... will open a new one for ya. sorry again...
0
 
CEHJCommented:
You can't do that 91mustang - it's against the rules. If you want you can ask CS to reopen this one.
0
 
91mustangAuthor Commented:
sorry nick, i tried, the mod will give you points on this Q
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.