473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Help from Date klassen

Hello!
I can convert from the given date,month and year to a day of year with the following code.

GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.set(1996,0,1);
System.out.println(cal.get(cal.DAY_OF_YEAR));
Answer : 1

My question is now i want to do opposite for eksempel i want to convert from the given year(1996) and a day of year(256) to date. How i can do that?
I need help .
Malik
Apr 3 '07 #1
8 1568
r035198x
13,262 8TB
Hello!
I can convert from the given date,month and year to a day of year with the following code.

GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.set(1996,0,1);
System.out.println(cal.get(cal.DAY_OF_YEAR));
Answer : 1

My question is now i want to do opposite for eksempel i want to convert from the given year(1996) and a day of year(256) to date. How i can do that?
I need help .
Malik
Create a new Calendar. Set it's Date to 1 January 1996. Add 256 to it's date field and you have the date.
Apr 4 '07 #2
Create a new Calendar. Set it's Date to 1 January 1996. Add 256 to it's date field and you have the date.

Problem:
I have just year(1996) and a day of year(256).I want to convert this into a date.I donot have month and date,that i am trying now. How i can do that?
I am very thankful to you.
malik123
Apr 4 '07 #3
r035198x
13,262 8TB
Problem:
I have just year(1996) and a day of year(256).I want to convert this into a date.I donot have month and date,that i am trying now. How i can do that?
I am very thankful to you.
malik123
Do you know how to set the Date field of a gc to 1 January 1996?
Apr 4 '07 #4
Do you know how to set the Date field of a gc to 1 January 1996?
I didnot understand but you mean

GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.set(1996,0,1);
Apr 4 '07 #5
r035198x
13,262 8TB
I didnot understand but you mean

GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.set(1996,0,1);
Isn't it supposed to be

Expand|Select|Wrap|Line Numbers
  1.  GregorianCalendar gc = new GregorianCalendar(); 
  2. gc.setTime(Date.valueOf("1996-01-01"));
  3.  
Check the docs for java.sql.Date and for GregorianCalendar.

then you can do gc.add(GregorianCalendar.DAY, 256);
Apr 5 '07 #6
I have tried but not found the correct result.

I tried to explain my problem once again. I have just two inputs Year and Day of year for example we have year "2007" and day of year "39".

From these two inputs i need following output.
I want to get the output in date,month and year which is "8 Februar 2007".How i can do that.
I am very thankful to you.
malik123
Apr 5 '07 #7
r035198x
13,262 8TB
I have tried but not found the correct result.

I tried to explain my problem once again. I have just two inputs Year and Day of year for example we have year "2007" and day of year "39".

From these two inputs i need following output.
I want to get the output in date,month and year which is "8 Februar 2007".How i can do that.
I am very thankful to you.
malik123
Have you been reading what I've been posting? What happened when you tried it?
Apr 5 '07 #8
I have found it.
The exact code is

int å=2007;
int d=39;
GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
cal.set(å,0,1);
cal.set(Calendar.DAY_OF_YEAR,d);

System.Out.println( (cal.get(cal.DATE))+"-"+(cal.get(cal.MONTH)+1)+"-"+å);

Result is : 8-02-2007

I have done it.Thanks for helping me.
malik123
Apr 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: - | last post by:
Hello to all I need help on some sql statements and wondering is anyone out there is able to help. I've extracted some data from the database into a new table consisting of 4 fields CustomerID...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
4
by: JonathanParker | last post by:
Looking for some help urgently with some VB SQL Access stuff. You'll have to excuse the messiness of the code, I'm a newbie at all this. I'm running this code with a selection of check boxes to...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
7
by: kr151080 | last post by:
Ok so I am messing around with a program and have no idea how to go about doing this but here is the code for the class date.... public class Date { private int dMonth; private int dDay;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.