Solved

# Date question

Posted on 2004-04-19
278 Views
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

0
Question by:91mustang
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 3
• 2

LVL 86

Expert Comment

ID: 10859872
Use a Calendar and set the appropriate fields
0

LVL 86

Expert Comment

ID: 10859884
0

LVL 9

Assisted Solution

Nick_72 earned 50 total points
ID: 10860006
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

LVL 86

Accepted Solution

CEHJ earned 50 total points
ID: 10860072
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

LVL 4

Author Comment

ID: 10860137
thanks :)
0

LVL 86

Expert Comment

ID: 10860198
8-)
0

LVL 9

Expert Comment

ID: 10860421
You're welcome
0

LVL 4

Author Comment

ID: 10860595
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

LVL 86

Expert Comment

ID: 10860627
You can't do that 91mustang - it's against the rules. If you want you can ask CS to reopen this one.
0

LVL 4

Author Comment

ID: 10860960
sorry nick, i tried, the mod will give you points on this Q
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

servlet example 11 77
check java version using powershell 13 474
ejb message driven bean mdb creation steps 2 54
Java array 21 150
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to aâ€¦
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the bâ€¦
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arrâ€¦
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
###### Suggested Courses
Course of the Month2 days, 18 hours left to enroll