473,404 Members | 2,137 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,404 software developers and data experts.

Date/Time part 2

Rob
Why is this not returning the right day or month? It gives me 5 when the
rightnow variable gives a 18.

import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar rightnow;
int t;
rightnow = Calendar.getInstance();
t = Calendar.DAY_OF_MONTH;
System.out.println(rightnow);
System.out.println(t);
}
}

Output =
java.util.GregorianCalendar[time=1074470212464,areFieldsSet=true,areAllField
sSet=true,lenient=true,zone=java.util.SimpleTimeZo ne[id=America/Denver,offse
t=-25200000,dstSavings=3600000,useDaylight=true,start Year=0,startMode=3,star
tMonth=3,startDay=1,startDayOfWeek=1,startTime=720 0000,startTimeMode=0,endMo
de=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0],firs
tDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2 004,MONTH=0,WEEK_OF_YEAR=4
,WEEK_OF_MONTH=4,DAY_OF_MONTH=18,DAY_OF_YEAR=18,DA Y_OF_WEEK=1,DAY_OF_WEEK_IN
_MONTH=3,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=56,S ECOND=52,MILLISECOND=464,Z
ONE_OFFSET=-25200000,DST_OFFSET=0]
5
Jul 17 '05 #1
2 2599
"Rob" <ta******@yahoo.com> wrote in message news:<Fv********************@comcast.com>...
Why is this not returning the right day or month? It gives me 5 when the
rightnow variable gives a 18.

import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar rightnow;
int t;
rightnow = Calendar.getInstance();
t = Calendar.DAY_OF_MONTH;
System.out.println(rightnow);
System.out.println(t);
}
}

Output =
java.util.GregorianCalendar[time=1074470212464,areFieldsSet=true,areAllField
sSet=true,lenient=true,zone=java.util.SimpleTimeZo ne[id=America/Denver,offse
t=-25200000,dstSavings=3600000,useDaylight=true,start Year=0,startMode=3,star
tMonth=3,startDay=1,startDayOfWeek=1,startTime=720 0000,startTimeMode=0,endMo
de=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0],firs
tDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2 004,MONTH=0,WEEK_OF_YEAR=4
,WEEK_OF_MONTH=4,DAY_OF_MONTH=18,DAY_OF_YEAR=18,DA Y_OF_WEEK=1,DAY_OF_WEEK_IN
_MONTH=3,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=56,S ECOND=52,MILLISECOND=464,Z
ONE_OFFSET=-25200000,DST_OFFSET=0]
5

Calendar.DAY_OF_MONTH is a constant with a value of 5.

Greg
Jul 17 '05 #2
"Gregory A. Swarthout" <gr******@xmission.com> wrote in message
news:5c**************************@posting.google.c om...
"Rob" <ta******@yahoo.com> wrote in message

news:<Fv********************@comcast.com>...
Why is this not returning the right day or month? It gives me 5 when the
rightnow variable gives a 18.

import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar rightnow;
int t;
rightnow = Calendar.getInstance();
t = Calendar.DAY_OF_MONTH;
System.out.println(rightnow);
System.out.println(t);
}
}

Output =
java.util.GregorianCalendar[time=1074470212464,areFieldsSet=true,areAllField sSet=true,lenient=true,zone=java.util.SimpleTimeZo ne[id=America/Denver,offse t=-25200000,dstSavings=3600000,useDaylight=true,start Year=0,startMode=3,star tMonth=3,startDay=1,startDayOfWeek=1,startTime=720 0000,startTimeMode=0,endMo de=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0],firs tDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2 004,MONTH=0,WEEK_OF_YEAR=4 ,WEEK_OF_MONTH=4,DAY_OF_MONTH=18,DAY_OF_YEAR=18,DA Y_OF_WEEK=1,DAY_OF_WEEK_IN _MONTH=3,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=56,S ECOND=52,MILLISECOND=464,Z ONE_OFFSET=-25200000,DST_OFFSET=0]
5

Calendar.DAY_OF_MONTH is a constant with a value of 5.

Greg


In other words, you didn't ask it to return the right day or month or
anything. You asked it to show the value of Calendar.DAY_OF_MONTH, which
Greg pointed out has a value of 5. What you're looking for is something
like:
System.out.println(t.get(Calendar.DAY_OF_MONTH));

I didn't look it up, but I think that's it. Your Calendar object is t. The
get(int something) method of Calendar returns the specified part of the
calendar. You specify which part by using the constants defined in Calendar.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
11
by: tohear | last post by:
ToOADate and FromOADate don't handle negative dates with time parts correctly. Negative dates with no time parts are OK. (Note: In COM date "zero" is 12/30/1899). Does anyone know if these are...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
1
by: brino | last post by:
hi all ! i have 2 fields in a form - a Date field & a Time field. these 2 fields have to be combined into the one field which has date & time. i know there must be some code to do this. i have...
1
by: Thorben Grosser | last post by:
Hey again newsgroup, I am still working on an archive database and got another problem: I have to classify the folders by a date or a date range which has the format mm/yyyy I got the feeling,...
2
by: Andrus | last post by:
I need to display and edit only date part in DataGridView column whose data source type is DateTime?. The following code shows and allows to edit also time part. How to modify this code so that...
11
by: Connie via AccessMonster.com | last post by:
Hi Access Building Friends, I am building a database for a manufacturer who needs to know the projected End_Date of each job. I know the Start_Date and the total days required to do the job. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.