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

1. How to get date picture created in java

I would like to extract the date a jpg file was created. Java has the lastModified method for the File object, but appears to provide no support for extracting the ...

2. Not able to retrieve dates

I am working with web Dynpro java.. I have created a stateless session bean wherin i have created business methods for inserting and retrieving records from my dictionary table. My table ...

3. Implementation Patterns: a function returns a Date, but it is reasonable that a date won't be found, return null or try to apply the NULL object patt...

So let's say you have a function that returns a date Date myFunc(paramA, paramB){ //conditionally return a date? } So is it appropriate to return null from this function? This seems ...

4. Identifying the season from the Date using Java

I've had nothing but good luck from SO, so why not try again? I have an application that needs to show a different image based on the season of the year (spring, ...

5. When are API methods marked "deprecated" actually going to go away?

I'm code reviewing a change one of my co-workers just did, and he added a bunch of calls to Date.toMonth(), Date.toYear() and other deprecated Date methods. All these methods were ...

6. Whats the best java date recurrence pattern calculator

Anyone know of a (reliable) date recurrence calculator, we're trying to implement something in our app which would allow a schedule to be created, similar to those for recurring meetings in Outlook. We ...

7. Simple Java Date Calculations

I would like to do simple date calculations in Java. For example, compute the difference in days between to dates (having a 0 time component). Of course you could do a ...

8. Getting today's date in java - I've tried the regular ways

I need today's date - and zero anything else (" 05/06/08 00:00:00 ") I've tried

Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.HOUR, 0);        
Date date1 = calendar.getTime(); ...

9. new Date("05-MAY-09 03.55.50") is any thing wrong with this ? i am getting illegalArgumentException

new Date("05-MAY-09 03.55.50")
is any thing wrong with this ? i am getting illegalArgumentException

10. "standard" Java DateBuilder implementation?

I'd like to know if there is a "standard" Java implementation of a DateBuilder before I build one myself. I have looked in the java API and Apache Commons and ...

11. How can I determine if a date is between two dates in Java?

How can I check if a date is between two other dates, in the case where all three dates are represented by instances of java.util.Date?

12. Date processing in Java

I have 2 strings which are actually dates but they are in different format:

  1. 2004-06-01 00:00:00 (This value I get from Excel database through JDBC)
  2. 6/1/2004
Is their any pre-defined Class in Java which ...

13. What's going on with Java's Date class? Is this a known bug?

I know Date is mostly deprecated, but I still use it form time to time (less code than using Calendar). I came across a truly bizarre bug, and I'm wondering if ...

14. number of periods (custom) between two dates

I want to find out how many periods (custom) are there between two dates. Like how many weeks are between 1 july to 2nd Aug or how many half months are ...

15. Java date function which is not deprecated

I simply need to print the date of the day on the console in this format: Day.Month.Year. Example: 03.10.09 Code:

GregorianCalendar c = new GregorianCalendar();
Date s =  c.getTime(); 
The console prints:
Sat Oct ...

16. Why is java.util.Date's setTime() method not deprecated?

All the other mutators got deprecated back in JDK 1.1, so why was setTime() left as is? Surely java.util.Calendar - the correct way to manipulate dates - can create new ...

17. Which method should I use?

I'm an intermediate java coder, writing a librarian Java app, and for some reason I just can't figure out whether I should use dueDate.after(today) OR dueDate.before(today) method as to deciding if ...

18. How do I say 5 seconds from now in Java?

I am looking at the Date documentation and trying to figure out how I can express NOW + 5 seconds. Here's some pseudocode:

import java.util.Date
public class Main {


19. Grouping objects by date: am I an idiot?

I have a list of objects called Activity:

class Activity {
   public Date activityDate;
   public double amount;
I want to iterate through List, group them by date and return ...

20. Java Compilation date, like C __DATE__

I need to automate getting the compilation date in a specific format into one Java Source file, like the C compilers DATE define, How?

21. How to keep up to date on available Java libraries?

I've been writing code verbosely for far too long, and stumbled onto Apache Commons IO last week. I've used a lot of Commons before, but never looked at IO, ...

22. Nullable date in Freemarker

This is a piece of my freemarker template:

I want it to work as following:
  • if needByDate is null, then write nothing
  • if it is not null, then write the date part
The above works ...

23. new Date(2009, 12, 9) is deprecated

What Can I used to replace this ? Thanks for your help

24. Is the first edition of Head First Java out of date?

Having searched for books for learning Java here on StackOverflow, I decided to pick up a copy of Head First Java from a local library. Sadly, only the first edition from ...

25. How to express "never" with java.util.Date?

I have a class with the fields "deletionDate" and "experiationDate" which could both be undefined, what would mean that the object is whether deleted nor has an expiration date. My first ...

26. What is the Best Practice for manipulating and storing dates in Java?

What is the Best Practice for manipulating and storing Dates e.g. using GregorianCalendar in an enterprise java application? Looking for feedback and I will consolidate any great answers into a Best Practice ...

27. Doubt in getting yesterday's date using java

Hi All:
I want to get yesterday's date using java. I have used the following code but it is giving different date each time, Please check whether the code has to be ...

28. Java version migration deprecated date methods

I'm migrating from Java 1.1. to Java 5. I notice that some methods have been deprecated e.g. java.util.Date has a getYear() method which is deprecated. My question is if the getYear() method is ...

29. java get date marker field(am/pm)

I need to get the field AM/PM in date object. How can i get it? This is my code.

String startTime ="01:05 PM";
 SimpleDateFormat sdf = new SimpleDateFormat("hh:mm aa");

 Date st = sdf.parse(startTime);

30. Why is this code displaying different dates?

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {

    public static void main(String[] args) throws ParseException {

        SimpleDateFormat datef = new SimpleDateFormat("dd/mm/yyyy");


31. Construct Date - An efficient way

May I know what is the most efficient way to construct a date object using a specific day, month, and year.

Date(int year, int month, int day) 
This construct is depreciated. Hence, ...

32. In java, Date() method returns a value. but I am confused in that

I used Date() for getting the date of my birthday, but it was returned the mismatch of the month. My birthday is 04-March-87. so i gave an input as,

Date birthDay= new ...

33. Epoch is not epoch if do a new Date(0L). Why?

My problem is pretty straigtforward explained : if i do this :

public class Main {

public static void main(String[] args) throws Exception {
        Date ...

34. how to get previous date in java

I have a String in format yyyyMMdd. Is there a simple way to get a String with previous date in the same format? Thanks

35. How to keep track of the change in date in Java

I have an application that needs to do some actions every date change say at midnight. Whenever the date changes the application should be said of the same. Any help regarding ...

36. Linear Regression and Java Dates

I am trying to find the linear trend line for a set of data. The set contains pairs of dates (x values) and scores (y values). I am using a version ...

37. OLEDate java implementation

I need a good OLEDate java implementation, and this one does not seem to be working. Is there any known good opensource implementations (like in apache commons)? If not, ...

38. problem of new Date(long), begin with Jan 01 01:00:00 CET 1970?

the java doc describe that the constructor Date(long date) constructs a Date object using the given milliseconds time value since January 1, 1970, 00:00:00 GMT actulely when i did new ...

39. How to determine whether a spread-sheet cell contains a date, or a real number?

When a cell in a spreadsheet contains a simple date (mm/dd/yyyy) the poi API flags the cell-type as 'numeric'. This is probably because spreadsheets ( IMO ) historically recognize only strings ...

40. Should we use the Date Object in java?

Should we use de java.util.Date object in java? It has so many Deprecated methods that is a little anoying to have to use a complex method to something that should be so ...

41. Digital self-signed certification update expiry date

I have a self-signed digital certificate created using java keytool command. Can i update only the expiry date of the keystore file, without creating new keystore? Pls help

42. Check a Date is between two dates in Java

One thing I want to know is how to calculate what date will it be 10 days from today. Second thing is to check if one Date is between two other Dates. For ...

43. Displaying Date Of Birth in java by using Date Util

I'm testing a Person class that models a person with name, address and date of birth. How do I set dob (date of birth)?
Here is my Person class:

import java.util.Date;
public class Person{ ...

44. java.util.logging: how to suppress date line

I'm trying to suppress output of the date line durinng logging when using the default logger in java.util.logging. For example, here is a typical output:

Jun 1, 2010 10:18:12 AM gamma.utility.application ...

45. What's wrong with this random date of birth generator?

I'm trying to write a random date of birth generator for a date of birth between 25 and 50 years ago. I'm stuck with Java 1.4 and am attempting to ...

46. Holidays - is there a java implementation?

I'd like to know if there is a jar-file out there that could do the following:

DateMidnight dateInQuestion = new DateMidnight(12,12,2000);
DateChecker.isNationalHoliday(dateInQuestion, Locale.ITALY);
If there isn't, why? Surely there are lots of properly based ...

47. Expiring date today in Java

I need to check if given date is after today 23:59:59, how can I create date object that is today 23:59:59?

48. Removing Date Comment from Apache's Ant PropertyFile Task

I'm using the propertyfile task shown below in my build script:

<target name="build-brand" depends="-init" description="Adds version information to branding files.">
    <propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/">

49. Is there a java class for constructing a cron expression using a date?

I need to build a cron expression based on user input from a form. So I have a datepicker and a select box to choose the frequency. I can build a ...

50. Why doesn't my date comparision return true?

The if below never triggers, so c.after(a) must always return false. However, if I uncomment the second println, I clearly see that a is > 20050214, as I expect. Date a = ...

51. Date ranges in swingx's JXDatePicker?

Does anyone know if it's possible to selected multiple days with swingx's jxdatepicker? I'm using swingx version 1.6.1 (which looks to be the latest).

52. How to remove sub seconds part of Date object

java.util.Date gets stored as 2010-09-03 15:33:22.246 when the SQL data type is timestamp, how do I set the sub seconds to zero (e.g. 246 in this case) prior to storing the ...

53. Dates before January 1st, 1970

The getTime() fetches the time in millis for a certain Date. Can this be used reliably for dates say in the 18th century. We use the millis and store ...

54. Minimum date in Java

What is the minimum date value in Java?

55. Java Date Error

I am getting date in following format, as java string: Sat Jan 01 00:00:00 CET 2000 i want to convert it to yyyy-MM-dd fromat. For this i am doing:

String strDate = "Sat Jan ...

56. Need two Date() values for Java task

This is a really simple request, but I am not quite sure the easiest/most efficient way of generating these two values. I need to write a script that will check whether ...

57. DateUtils.parseDate doesn't throw ParseException on invalid dates = org.apache.commons.lang.time.DateUtils.parseDate(value, new String[] { "mm/dd/yyyy" }); If you give an invalid date string (e.g. value = 13/02/2000 or value = "12/35/2000"), this didn't result in an error (e.g. 13 as ...

58. How would you represent date of birthday in your java model?

And wait, don't rush to answer "java.util.Date", consider the following scenario. Person object having 2 fields: "birthday" and "nextMeeting" both java.util.Date. Now birthday stored in database as date type column (no time) for ...

59. JSON date to Java date?

I could not find this anywhere. I fetch some JSON from an API that returns standard JSON dates. You can see the format by running this code in a JavaScript console:

> ...

60. Date as double digit

I've a code to get year, month and day for one of my application.

    package com.cera.hyperionUtils;
import java.util.*;

public class HypDate {

 public static int curdate(int field)
  //1. ...

61. Get a page's last modified date using Java

Is there a standard way to tell when a page was last modified? Currently I am doing this:

URLConnection uCon = url.openConnection();
uCon.setConnectTimeout(5000);   // 5 seconds
String lastMod = uCon.getHeaderField("Last-Modified");
System.out.println("last ...

62. Is there a tool to see check-ins for all projects in Subversion by commit date and commit person

I want to know If there are any plug-ins or tools to see the files commited to the subversion by date and committer. we are using subversion. It will be nice, If ...

63. Is there any java class to get Date from cron expression

I need to find out the first occurrence of Date and time represented by given cron expression. Is there any java class, utility code which can help in getting data object from ...

64. Checking if a date exists or not

Is there any predefined class in java such that, if i pass it a date it should return if it is a valid date or not......... say for example if i ...

65. Checking the validity of a date

If I am given some random date, then I need to check if that date really exists or not and then display true or false. I need to return false for ...

66. how to inceament date

Possible Duplicate:
read line using java & maped filterd data
  • i hav below text file
  • in my java code it is filtered below output.
    11/2/2010    cat    ...

67. How to get the past Sunday and the coming Sunday in Java?

I asked How to detect if a date is within this or next week in Java? but the answers were confusing, so now I think if I can find the ...

68. Incorrect date extracted from SVN using SVNKit

I am using SVNKit to retrieve logs from a SVN server. I am using SVNKit version 1.3.2. Everything is working fine and well except for some bizarre problem that I have been ...

69. Java: Iteration of given Dates

I have two dates in Java:

Wed Jan 05 00:00:00 CET 2011
Sat Jan 15 23:59:59 CET 2011
Now I want to iterate over them, so that every day I can do a System.out.println() ...

70. Java date jump to the next 10th minute

I need a fast implementation of a "Date jump" algorithm that is to be included in an event management system.
An event is triggered and sets a date (in a synchronized method) ...

71. Date exception when trying to use date method

I have defined a object model where one of the array elements is a string

public static String[] columnNames6
          = {"Total Shares",

72. How to covert date from MM/YYYY to MM/DD/YYYY in Java

I want to convert date from MM/YYYY to MM/DD/YYYY, how i can do this using SimpleDateFormat in Java?(Note: DD can be start date of that month)

73. How many bytes of memory does a java.util.Date object use?

I need to store a large amount of dates (potentially large enough that the amount of heap space used is a concern so please, no lectures on premature optimization), and I'm ...

74. How to keep the Date(0L) return the same result between different computer

I found out that different computer return different result from the following statement in Java.

private static final Date ORIGIN = new Date(0L);
In my computer, it return the following ...

75. Java doubt on unique date issue

In a loop, I am to create a new object only if the date is different than the previously iterated value. Otherwise i want the same object. Can anyone help?

76. How to get today's Date?

In other words, I want functionality that provides Joda-Time:

today = today.withTime(0, 0, 0, 0);
but without Joda-Time, only with java.util.Date. Methods such as .setHours() and etc. are deprecated. Is there are more correct ...

77. java Calender/formatter provides wrong date

Somehow I am being reported a issue, in which following code provides date in future. The timezone used is GMT+01:00. The numberOfDays is non negative integer. The intention of this code is reduce the ...

78. Java: I need help on Date class

// Date3 class declaration.

public class Date3 
   private int month; // 1-12
   private int day; // 1-31 based on month
   private int year; ...

79. How should date properties be defined in a java class?

I have a simple java object with several date properties and I always seem to change my mind on how to define them. Should the properties be defined as date objects ...

80. Date Best Practice

I have the following problem. I have a quartz job that runs every 5 minutes and makes a web service call retrieving a large object. The purpose of this application is ...

81. Intialize JXDatePicker with custom date

I want to intialize a JXDatepicker with a custom date. At the moment I´m trying this:

    Date date1= new Date(2006-01-01);    
    Date ...

82. How can I make Jackson deserialize a Long to a Date Object?

I'm serializing some java.util.Dates within a Map. The dates are serialized into Longs (Jackson writes the Long value of the Date instance to the JSON string), however, they're not being de-serialized ...

83. Highest date in java

How to get highest date among given set of dates in java in a jsp

84. Java Date Formatter

I am getting date format as "YYYY-mm-dd hh:mm" as formatter object. How can i format the input formatter object to get only "YYYY-mm-dd"; Regards, Raju

85. Record lost when using date as key for TreeMultimap in Java

I am writing a scheduler where events created are tag to the date. Thus by selecting a date, all events tagged to the date will be shown. I tried doing this ...

86. Java: Why is Date deprecated, and what do I use instead?

I come from the C# world, so not too experienced with Java yet. Was just told by Eclipse that the Date was deprecated.

Person p = new Person();
p.setDateOfBirth(new Date(1985, 1, 1));
Why? And ...

87. Date d = new Date(0L); what is 0L mean in this Date?

Date d = new Date(0L); 
what is 0L mean in this Date d?

88. problem in java with date

I have a problem in java with sql date. I have the value of year-y, month-m,day-d i create new Date(y,m,d) but it says that this constructor is depricated and it returns ...

89. again problem with java date

I want to know the number of days of date, the getDay() method returns wrong answer, how can i know the correct number of days ?

90. How to set an expiration date in java

I am trying to write some code to correctly set an expiration date given a certain date. For instance this is what i have.

    Date lastSignupDate = m.getLastSignupDate();

92. Java Date issue

I am using GregorianCalander and when i tried to get todays date using the following code i am getting a date which is backdated to one month. The code i have ...

93. how to get Century from date in java

How to get current Century from a date in Java ? For example the date "06/03/2011" according to format "MM/dd/yyyy". How can i get current century from this date using SimpleDateFormat?

94. How deserialize, if lack of some date?

We have two systems: external and internal, which are sharing information in JSON format (GSON library). Information from an external system comes in internal and processed here. Everything was very good, coming from ...

95. Good Reason to use java.util.Date in an API

Are there any specific reasons to use a Date class in an API (for example, in an employee birth date field) rather that a long or Long. There is some discussion ...

96. Want only date from epoch

Given millis since epoch, I want an instance with the fields Month, Date, Year filled out, with the hour minute seconds set to some default values. What is an efficient way to ...

97. How can I perform arithmetic operation with dates in Java?

Possible Duplicate:
How to calculate time difference in java?
Actually I want to subtract two dates in Java. I tried a lot but can't succeed. ...

98. Developing a simple utility class( like a Date class )in java

I am a college student. In our college we have to develop a simple Date class in Java similar to the one available in java.util package. If we do that then what are ...

99. XSSF POI is cell date

Is there a way to determine if cell is a date? I know about style.getDataFormatString() but that doesn't help me, because I can't determine if is formating is for date or not.

100. weird issue coverting millisecond to java Date

hi im trying to convert a date value in milliseconds granuality into java Date using
new Date( millsecs) the converted value i get is 3 hours behind what it is supposed to be. I ...