date 2 « Date Time « Java Data Type Q&A

1. java.util.Date's behavior

Foo a;
Date b = a.getDate();
Date c = new Date(b.getTime());

if (b.equals(c)) System.out.println("equal");
else System.out.println("not equal");

The above prints:
not equal
2011-07-23 22:24:21.834
Sat Jul 23 22:24:21
Why is this? Is this a bug in Date? Thats hard to ...

2. Creation date in JavaDoc

I'm developing a Java library and I'm trying to define a good Header through JAutoDoc. It works fine but I can't figure out how to automatically define the creation date of the ...

3. java datechooser how to get date

        DateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
    String nowYYYYMMDD = new String( dateformatYYYYMMDD.format( dateChooser.getDate()) );
i tried this way ...

4. how to create a Java Date object of midnight today and midnight tomorrow?

In my code I need to find all my things that happened today. So I need to compare against dates from today at 00:00am (midnight early this morning) to 12:00pm ...

5. How to get the date of every sunday

Possible Duplicate:
How to get all dates of sundays in a particular year in Java
How can I get the date of the coming Sunday?, I ...

6. How I classify an word of a text in things like names, number, money, date,etc?

I did some questions about text-mining a week ago, but I was a bit confused and still, but now I know wgat I want to do. The situation: I have a lot ...

7. Java library to support dates with limited precision (like year/month only)

In some system I have to operate on dates which may have limited precission (like month and year only or year only), e.g. "2001" or "January 2011". I need to know ...

8. How does Java's date work?

Hi I have a following code below:

public Date convertFromGMTToLocal(Date date) {
     return new Date(date.getTimezoneOffset() + newOffset*60*1000);  

public Date convertFromLocalToGMT(Date date) {
    return new ...

9. Java new Date() in print

just learning Java and I know this may sound stupid but I have to ask.

System.out.print(new Date());
I know that whatever is in the argument is converted to a string, the end ...

10. A Date object capable of storing microseconds

I'm looking for a Date object capable of storing down to microsecond granularity, does anyone know of one? The standard Date object only stores down to milliseconds (I know that this ...

11. Why is my date not displaying properly?

I used SimpleDateFormat:

SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
value.adStartDate = df.parse("2011/11/11 11:11:11");
I was hoping the date would come out like the string I provided, ...

12. Java returns Date object to Flex incorrectly

I am using Flex,GraniteDS and Jav?. Flex is sending Date correctly in Daylight saving time for example "September 10 10:00:00 UTC-7", but after all I am receiving the same date but ...

13. Java Date object problem

I'm doing a java program that will take an action based on the date and time. the problem is that when I used the java.util.Date object i found that it is affected ...

14. What is the use of "lenient "?

Here "lenient " is used in Java DateFormat, i checked the doc. but didn't get. Can any body please tell me what is the use of this "lenient ", with one real ...

15. How Implement Date when the object created in Java?

It's an homework. I have to implement the following: private Date dateCreated which store, when the object was created.

private Date dateCreated;
getter method for dateCreated.
public Date getDateCreated() {
    return dateCreated;
And ...

16. Date parser for all formats

I have date formats like this which I want to parse -- 02 September 2011 15:57 Friday, September 02, 2011 9:51 AM Mittwoch, 10. August 2011 16:31 woensdag 10 augustus 2011 14:09 Wed, 27 Jul ...

17. Comprehensive (Intelligent) Date library

I'm looking for a complete Date management library in java that would allow me to understand strings like :

  • Tomorrow at noon => 2011-10-20 12:00
  • Today at 4pm => 2011-10-20 16:00
etc... But it would ...

18. Date Computaion in java

The date format iam using is "MM/dd/yy" I want to perform a operation like This:

LastActDate = Todaysdate -(PrchaseDate + 1) 
In myDb the date is stored as 2011-07-08 19:30:06(java util date

19. Java Date(0) is not 1/1/1970

I was expecting this to print 1970-01-01-00:00:00, but it prints 1970-12-31-19:00:00 What am I misinterpreting about how Date is counted from? It is one year off. I am running this ...

20. GsonBuilder setDateFormat for "2011-10-26T20:29:59-07:00"

I'm getting a date/time in json as 2011-10-26T20:29:59-07:00. What's the proper way to use gsonBuilder.setDateFormat to properly format this time?

21. How do I suppress the date line from 2-line java.util.logging output?

I'm using the Java default logger, and right now it's printing a lot of useless trash to the output, here is a example, this line of code:"Logging pointless information...")
Will output all ...

22. Does twitter4j provide the capability to search tweets between 2 dates

Does twitter4j provide the capability to search tweets between 2 dates (e.g. 2011-10-27 05:30:00 to 2011-10-27 06:30:00) currently it seems to have the granularity of a date and not hours or minutes. ...

23. wierd behaviour of date object

 SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
 Date date = dateFormat.parse("11/04/2011");

Tue Jan 04 00:11:00 IST 2011
When output the date object it shows as january instead of november. But when format ...

24. Printing date in java with ordinal characters

Is there a way in Java you could format a date with the ordinal characters at the end of day something like : 1st of july ? I have searching all over and could ...

25. java-apns with expiry date

I am using notnoop's java-apns to send iOS Push Notifications. This is the code I'm currently using, and it works great:

PayloadBuilder payloadBuilder = APNS.newPayload()

26. why is it a good idea that X.509 digital certificates have an expiry date?

I would like to know what is the benefit of having an expiry date

27. java - determine if a date is binary

I have a program that calculates whether or not a date entered by a user is a leap year or not. I think I got that all down but I also ...

28. Java Generate all dates between x and y

I attempted to generate the date range between date x and date y but failed. I have the same method in c# so I tried to modify it as much as ...

29. Writing dates and int's to an existing .pdf

I have an existing pdf that I am filling out dynamically in java. I have all the fields that require strings set up and working, but the fields that use ...

30. Java Date localization

How can I set the localization so that java.util.Date have the German format? ( ie: ) . I need to send to a Webservice a Date(), but it can be ...

31. date generation

hai i am meyis i need a java program code for date generation.(mssql-back end) Fields are fromdate and todate both field are datetime datatype. Button:-save,cancel,exit both dates are given by the ...

32. Date Checking

Success! After a few attempts at different potential solutions, the below appears to have worked, didn't even need to use a calendar in the end : Date oneYearAhead = new Date(); ...

33. how to get date of birth from identification number?

I would like to identify the Date of Birth, Gender and Age of a Malaysian by extraction the information from the new IC number. The object calculate the Date of Birth, ...

34. I need some help with a date program can anyone help?

Frinavale re: I need some help with a date program can anyone help? Well this is a classic situation where inheritance would be used. There is already a Date class. It ...

35. Date Calculator

How would I create a very basic Java program when a users enters a certain date and wants to add a specific amount of days to that date the program will ...

36. how can i reformat a Date object

37. Date Localization

Hi All, I have a Date stored in GMT format in database. Now I need to display this date to user depending on his/her LOCALE. I found SimpleDateFormat and few other classes to convert the Date Format, but I am not able to find how to change the Date value as per user locale. Example: Date in database : 19 August ...

38. date conflict

I am entering system date .. java.sql.Timestamp ApprovedOn= null; java.sql.Timestamp currDate = UtilClass.getSystemDateTime(); ApprovedOn = currDate; pstmt.setTimestamp(16, ApprovedOn); At this time it is entering time perfectly. like 3/31/2005 5:42:21 PM But when i fetch this value it is showing time with AM. Please Help me i am at Client side Very urgent.with code please Thanks in advance

39. Customized date separator

Hi , Is there any way to get the customized date separator that has been set by the user in the windows regional settings. As the regional settings provides an option to customize the date separator and other date characters the Locale object does not retrieve the accordingly set characters it only returns the defaults of that Locale

40. Mid-date of two dates

41. problem with new Date()

Hello all, I have a strange problem that I cannot figure out and need your help. I save a date in the database without time (i.e. 00:00:00), when i read it i get back (796600800000) Date=Fri Mar 31 01:00:00 IST 1995 Where the hell did the 01:00:00 come from ??? HELP !!! TIA

42. a problem with Date class

43. Subtracting from java.util.Date

Hi, I am looking for date functions which will allow me to subract 1 day, 1 week, 1 month, 3 mths, 1 year. Date now = new Date(); From now, I want to subtract 1 day, 1 week, 1 month, 3 mths, 1 year. I searched the the java.util classes. java.uil.Calendar has a add() method but it doesn't return a java.util.Date ...

44. How to check a date as 'holiday' in java

Java's GregorianCalendar class knows nothing about holidays, since thay are particular to a location, and subject to change. What you could do is create a static data structure containing all the dates which constitute a holiday in whichever location your application is being run (you will have to populate this manually) and check dates against it. For example you could have ...

45. java.util.Date version conflict

in jdk1.3 java.util.Date has a member of Calendar which in turn has java.util.SimpleTimeZone. However in j2se 1.4 onwards this has changed to sun.util.Calendar.ZoneInfo Due to this some of our webservices code which was running smoothly has started giving issues with the 1.4 version. Any idea how to resolve this version conflict and fix the issue ? Has anyone faced similar problems? ...

46. Dates in forms

I don't think a general solution is possible. Not least because even a human can't reallyt know whether 01/03/01 means the 1st of March (European Style) or 3rd of January (US Style), and that's without even considering which century to use for the year. The best way I have seen of entering dates is to use one of the many pop-up ...

47. Select date field problem

48. java date

i want to subtract date of previous month which is store in database from current date to get days because i want that if any record in data base after 15 days from the date when it is inserted should be deleted .we know that date is returned in a we can not subtract it.if we can take differen dd ...

49. Problems in accessing the Date Field

51. Date Problem

i am using the calendar class to display the date on my JSP; i am rolling my day back by one day by using the command if (true){ cal.roll(Calendar.DATE, false); } now, it is rolling only the date but not the month and this is creating descrepencies; Condition 1: when the date is not the first day of the month, this ...

52. EVIL DATES. Need help

53. Date - easy question, make yourself feel good

Very quick question - I want to convert the format of a date/time. I retrieve a msec value from a database, but instead of displaying it as a msec value in an html page, I want to display it as a normal time (e.g. 12:22). I have managed to display it as a full date and time (that is, Sun Jul ...

54. How to get all request stored in databse between two date

I am having a servlet in which i am I accepting two form values i.e 'fromdate' and 'todate' by using req.getParameter(fromdate & todate). Now i have to query a table called REQUEST which has 4 columns like req_id, name, createdate and status. In the servlet I would like to retrieve all the request during that period say for example. between 1st ...

55. system date

56. Can I pass a java.util.Date value as an attribute of a tag?

Are you sure? If you look at the Tag tutorial on JavaSoft and my app server (Resin) also complains This what the tutorial has to say. Tags With Attributes The start tag of a custom action can contain attributes in the form attr="value". Attributes serve to customize the behavior of a tag just as parameters are used to affect ...

57. A simple date question

Hi, I made the following menu to let user input date info and I added to the jsp page. <% String year = ""; String month = ""; String day = ""; %>

58. date returning null

try using public void setLenient(boolean lenient)Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format. Parameters: lenient - when true, parsing is lenient See Also: Calendar.setLenient(boolean) parse will throw a null pointer exception ...

59. Problem with Date Object

61. how can i reformat a Date object

62. updating date field

I have got to update a date field from java. vSql = "UPDATE R5PERMEVENTS SET PEV_DATE ='" +new java.sql.Date(vCurrentDate.getTime())+"' WHERE PEV_ACTIVE = '+'"; Now the problem is : new java.sql.Date(vCurrentDate.getTime()) returns values as'2004-07-30 so the query becomes: UPDATE R5PERMEVENTS SET PEV_DATE ='2004-07-30' WHERE PEV_ACTIVE = '+' Now the oracle doesnot underatand the date format. How do i change the query in ...

64. Date Localization

65. getting today's date

Hi, I need to get today's date and insert into sql table. Date d = new Date(); long today = now.getTime(); when I insert this value into sql table hour:min:sec is also inserted. please give me suggestions to get today's date in long value or in timestamp value without hr:min:sec attached to it. thanks,

66. Max Date Limit

When I create a Date object after parsing like... String eDate = "27-AUG-24"; SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy"); ParsePosition pos = new ParsePosition(0); sdf.setLenient(false); java.util.Date endDate = sdf.parse(eDate, pos); System.out.println(endDate); When printing the endDate I get the date as Wed Aug 27 00:00:00 GMT+05:30 1924 Works fine till 26-AUG-24. But when I do the same after changing the date format like... ...

68. java dates

you can use java.text.SimpleDateFormat class to format your date. get the milliseconds by using sdf.getTime(). convert your 4 days into milliseconds and then take the difference. and format it again to represent a date. enjoy. Moreover, read the javadocs for SimpleDateFormat. it will guide you through [ September 08, 2004: Message edited by: adeel ansari ]

69. Bitwise Operators and Date Help

I found some code used as an example of how to get the time since 1900 and unsinged 32 bit number for implenting a time server. long differenceBetweenEpochs = 2208988800L; long msSince1970 = now.getTime( ); long secondsSince1970 = msSince1970/1000; long secondsSince1900 = secondsSince1970 + differenceBetweenEpochs; byte[] time = new byte[4]; time[0] = (byte) ((secondsSince1900 & 0x00000000FF000000L) >> 24); time[1] = (byte) ...

70. date question

71. Date problem

Hi, I have a problem getting the day from a string. I hope somebody can help me. here is my sample code: String currDate = ""; String month = ""; String year = ""; for(int i=1;i<=31;i++){ currDate = year+"-"+month+"-"+i; } I want to display only the date without the month and the year and get the day of that particular date. ...

72. Handling Multiple Date Formats Elegantly

I'm working on an application which utilizes dates. One example is a person's date of birth. I read this data in as a String and then need to convert it to a Date object. I was planning on using the SimpleDateFormat class to do the conversion for me, but my problem is that people couple type in multiple date formats. For ...

73. Problem with java Date !!!!

Hi, I have an application in which when I call for existing date value in my database(I specified only date with time in Hrs and Mins in database) I get date exactly with time but I'm also getting seconds which I have not given in database. When I get the same date again, I get a different seconds value ! Is ...

74. how to break date

hi.. can anybody pls tellme how to break the time i get from getTime() method of Calendar class as it retuns in this format Thu Jan 06 01:43:35 IST 2005 but i wanted hours separate, minutes separately, and seconds separetly.. pls tell me how to do that ? as i m making a sheduler program i have to check after every ...

75. about dates

76. Get the system date

Hi all, I want to get the System date,month,year. Also Iwant to to something like this. 1. want to get the 1st day(monday or tuesday etc..) of a particular month. 2. want to get how many dates are there in a selected month. can u plz send me those things. Thank you. Sajeevi.

77. date problem

hi.. i need help in converting string to date.. i just need someone to check whether my code is correct or not.. here are my codes: Date today = new Date(); DateFormat formatLong= DateFormat.getDateInstance(DateFormat.SHORT); java.sql.Date curDate = java.sql.Date.valueOf(formatLong.format(today)); //and below is the storing part.. String query1 = null; query1 = "Insert into ITS.dbo.orderDetails values(?)"; PreparedStatement stmnt = conn.prepareStatement(query1); stmnt.setDate(1, curDate); stmnt.executeUpdate(); ...

78. Tommorows date

Hi , I know that this is simple for most of the folks..but i cant get it right... Well I want to get the next days date (i.e, tommorows date) And the format i want is "yyyy-MM-dd" How can i get at the solution..I tried it with Calendar ,gregorian... but somehow didnt materialise.. Thnks in advance, A kumar

79. how can i get yesterdays date?

Calendar cal = new GregorianCalendar(); // creates with today's date cal.add(1, Calendar.DATE); Date yesterday = cal.getTime(); sure u dont "add 1" ?? should that be a -1 ?? i just after found these on the web. I'll try the three. Thanks for replying. Calendar theDate = Calendar.getInstance(); // returns a new locale-specific calendar set to the current time. theDate.add(Calendar.DATE, ...

80. Date Question

I have a date question. Which is better Date or Calendar for the following application. I want to get today's date. I then want to add an amount of days to that date for a projection. For example, let's say today is April 15 and I want to do a projection that is from today's date to say, 25 days from ...

81. Strange date effect

Morning y'all. I'm retrieving a string from a webform and processing it in a servlet. Testing has revealed a rather odd effect; if a supposedly invalid date such as "01/14/2005" is input the code accepts this as 01 Feb 2006. Equally "01/17/2005" is accepted as 01 May 2006. The java seems to be just adding the any extra months after 12 ...

82. Date problem

I am having a problem retrieving dates. I have a Java class in which I am retrieving dates from an Oracle database. When I call the Java class directly, I a getting the date correctly, but when I call the Java class from Tomcat, the time too is getting appended to the date as 00:00:00. The database entry contains only the ...

83. java Date questions

1. Please let me know about this Date stuff in Java.Any good pointers. 2. If i have a Date string in UI, how is it converted to Java database Date object. If i have on UI mm/dd/yy it's US format it will be saved with no problems. But if I accept the date on my UI from user in European format, ...

84. Yesterdays Date

85. Problem with the date 2005-07-14

Hi I am having a problem with a date being passed as 2005-07-14 from a String Array of selected dates. Here is my code: private String getMaximum(String[] array) { int maximum = 0; if (logger.isInfoEnabled()) {"WizardReportForm getMaximum()"); } if (array != null) { for (int index = 0; index < array.length; index++) { int value = Integer.parseInt(array[index]); System.out.println(value); System.out.println(maximum); if ...

86. Retrieving Date

87. Simple Date Formatter

The following piece of code newValue = formatter.parse(new String("").trim(), new Pa rsePosition(0)); returns null in java 1.4 but returns unix epoch time in java 1.3. Can any of you confirm if there has been such a major change in implementation of SDF from 1.3 to 1.4? If it has where can I find the documentation? Cheers Rimjhim

88. Name, Address & Date Matching

I'm working on a project that involves OCR input and matching parts of that input to existing data. What I need to match comes in three forms, a name, an address or a date. I'm looking for some help finding some of the best techniques to do this. Currently I'm getting fairly decent matching. I've used the following techniques for the ...

89. handling Date Cell in POI eventuserModel

Hi I 'm using POI api (evenmodel) to read the excel sheet. In Excel, date value been stored as the double value. for both Date value and Number value, there is a event/record object called NumberRecord and i 'm getting double as the retun value from that NumberRecord object. but i need to get the date value from this record. I ...

90. java.util.Date problem

There are two possible alternatives to this: a. Create calendar objects and compare the relevant fields of the calendar instances (day, month, year...). b. Change the code to something like int tolerableDifference = 24 * 60 * 60 * 1000; // milliseconds return Math.abs(beginDate.getTime() - selectedDate.getTime()) < tolerableDifference; Here, it should return true only if they represent the same date upto ...

91. Date Problem

Hi, can anyone suggest any clue on this. if (login_time != null) { java.util.Date loginTime=new java.util.Date(login_time); login_count=login_count+1; minDiff = currDate.getTime() - loginTime.getTime(); System.out.println("0148*vr2*minDiff:" +minDiff); minDiff = minDiff / (60*1000); //convert to minutes System.out.println("0150*vr2*minDiff:" +minDiff); } else { out.println("

The page is Empty.

"); System.out.println("0154*vr2*minDiff:" +minDiff); } the login_time is a Oracle DB date.the else PART is not working.THe error it generates: java.lang.IllegalArgumentException at ...

92. java.util.Date jdk 1.3 / 1.4

Hello, I compile and run following code lines Long l = new Long("781999200000"); java.util.Date d = new java.util.Date(l.longValue()); System.out.println(d.toString()); RESULT: - JDK 1.3.x Thu Oct 13 00:00:00 CEST 1994 - JDK 1.4.x Wed Oct 12 23:00:00 CET 1994 Doing that with year 2005, the results JDK 1.3 and 1.4 are equal! Does anybody know why JDK 1.3 has CEST ...

93. Date calculations

Here is what I have: Calendar calendar = Calendar.getInstance(); calendar.set(2005, 10, 31, 0, 0, 0); System.out.println(calendar.getTimeInMillis()/1000); calendar.set(2005, 11, 01, 0, 0, 0); System.out.println(calendar.getTimeInMillis()/1000); When I construct the above 2 dates, I get the same time in millisecs (1133424000). As far as I know, Oct. has 31 days in it and was wondering why I am getting the same millisecs for Oct ...

94. Date

95. How to get Yesterday's date

Stuart, do you know if this would work properly in areas with Daylight Savings Time, where the number of hours in a day ends up being 23 hrs for one day in the spring and 25 hrs for one day in the fall? You may also have problems if the system clock is changed (say, for example, to sync with some ...

96. Date Computation

Hi, I know this is very basic in Java. But if you guys don't mind I would like to add how to compute the difference of two given dates(For getting the age). In PHP, you can just specify (aDate - today). I'm just a little curious if you could just subtract 2 Date objects directly and have the same effect? Or ...

97. getting the correct Date problem

Hi friends i hav a date in string variable . i want one day extra to that date.For that i m using java.util.Date . But i am not getting correct month. Here is my sample code. public static void main(String[] args) { String to="23/05/2006"; System.out.println("input:"+to); SimpleDateFormat dateformat=new SimpleDateFormat("dd/mm/yyyy"); String to_str=null; try{ java.util.Date todate=dateformat.parse(to); System.out.println("Date:"+todate); //long msec=todate.getTime()+24*60*60*1000; }catch(Exception e){ e.printStackTrace(); } } ...

98. Regarding the date obtained using java.util.Date class

Hi, i am using the date obtained using java.util.Date class for my application.What i would like to know is that whether it gives the system date or some other date?? Because if its system date then obtaining the current date like that is useless for me as the user can change the system date & enter some other date?? So if ...

99. How to get next date of a given date

100. A question on java.util.Date

Hello! I have a method returning String value containing current day of month. public String currDay(){ simpleDF = new SimpleDateFormat("dd"); currDate = new Date(System.currentTimeMillis()); String currDay = simpleDF.format(currDate); return currDay; } How can I make it return a Date value containing days only? In a word I need a method returning Date value containing days only? Waiting for reply........... Thank you! ...