add « Date Time « Java Data Type Q&A

1. Java , adding minutes to a Date , weird anomaly

With Java Version 1.5.0_06 on both Windows and Ubuntu Linux : Whenever I add minutes to the date "2008/10/05 00:00:00" , it seems that an extra hour is wrongly added. ie: adding 360 ...

2. how to convert string into time format and add two hours

I have the following requirement in the porject. I have a input field by name startdate and user enters in the format YYYY-MM-DD HH:MM:SS. I need to add two hours for the user ...

3. How to add one day to a date?

I want to add one day to a particular date. How can I do that?

Date dt = new Date();
Now I want to add one day to this date.

4. Adding a number of days to a JodaTime Instant

I'm trying to write a simple utility method for adding aninteger number of days to a Joda time instant. Here is my first stab.

 * Adds a number of ...

5. Adding java time objects

How do you say, add 1 hour to a given result from calendar.getTime?

6. Why does an hour get added on to java.util.Date for dates before Nov 1 1971?

The following code appears to demonstrate a bug in java.util.Date whereby an hour gets added on if the local clock is set to GMT with DST adjustment on and the time ...

7. adding days to a date

I have a program that needs to start on 1/1/09 and when I start a new day, my program will show the next day. This is what I have so far:

GregorianCalendar startDate ...

8. adding date to Java util logger fileHandler name

Hi I currently have this in my .properties file: java.util.logging.FileHandler.pattern = %h/programName%u%g.log I would also like to append a timestamp / username to this so its easy to identify log files does anyone ...

9. How to add days to a date in Java

I want to add days to a date to get a new date in Java. How to achieve it using the Calendar class.

Calendar dom = new GregorianCalendar(d, m, y);
is the instance ...

10. Adding n hours to a date in Java?

I'm trying to add n hours to a Date for a program, but I don't know how I can work with hours. I found on this site a question about this, ...

11. Problem adding minutes with plusMinutes

I'm trying to add some minutes to a date using plusMinutes, but it just doesn't add anything at all: Here's the code:

    String currentDate ;
    SimpleDateFormat ...

12. Add date by one

hii all I have date in string form I want to convert it into first date form and increase date to one like 12-12-2000 to 13-12-2000 and want to re convert that increased date ...

13. How to convert a string to Date and then add it to excel using jexcel api

I am currently reading a CSV file. I have to extract the dates from it and add them to excel file in dd-MM-yy format. I am faced with two problems.

  1. I am ...

14. How to add an hour to my time

I have my time in the below format, and I use this value to set the text of my button.

String strDateFormat = "HH:mm: a";
SimpleDateFormat sdf ;
 sdf = new SimpleDateFormat(strDateFormat);
Now my ...

15. The best way to add a time span (long and TimeUnit) to a java.util.Date?

I'm trying to implement this method:

 * Adds the given span to the given date and returns a new date.
public java.util.Date add(java.util.Date d, long span, java.util.concurrent.TimeUnit unit) {

16. How to add the difference of two Dates to the third Date in Java?

I'm new to Java, and I did some search in google and this forum, but I'm still not sure what is a good way to do this. (Joda time is not ...

17. Java checking no of days in a month and adding dates that are missing

Hi I have the following arraylist strings of dates ["2010-08-01","2010-08-02","2010-08-04","2010-08-05","2010-08-06","2010-08-07","2010-08-08","2010-08-09","2010-08-11","2010-08-12","2010-08-13","2010-08-14","2010-08-15","2010-08-17","2010-08-18","2010-08-20","2010-08-21","2010-08-26","2010-08-28","2010-08-29"] I have 2 aims that I want to achieve, 1) how to get the number of days for each month based on the year ...

18. java add hours to system date and in yyyyMMddHHmmss format

I am getting input as some date/time in hours(integer) eg: 2 hrs I want to add this input hours to system date in yyyyMMddHHmmss format. How can i do this?

19. Adding 30 days to date giving one day less

I am adding 30 days to a date but its giving me 1 day less. i.e. if I put 20 oct 2011 then it is giving 19 Nov 2011 one day less ...

20. Add a date to now by parsing the input

I'm having an hard time trying to parse date in the future, and I would apreciate some help! Here's the thing, I'd like to add a parsed date to the current date ...

21. java how to add seconds to timestamp

i fail to add seconds to java Timestamp i have this but it gives me the same date:

int sec =600;

java.sql.Timestamp ts_from_ws = new java.sql.Timestamp(retry_date);
Calendar cal = Calendar.getInstance();
java.sql.Timestamp ts_new_date_ws = new java.sql.Timestamp(cal.getTime().getTime());

22. Adding time to date format in java

Possible Duplicate:
How to set time to a date object in java
I Have Date like 2008-12-10 00:00:00.000 and the Time is as 13:47. I want to ...

24. Adding three weeks to a date

I need to compute several dates based on another date. I understand how to use the GregorianCalendar to add weeks to another GregorianCalendar object, but I have a date. Is it really necessary to get each portion of my date in order to instantiate the GregorianCalendar object? I don't see where the constructor takes a date. Any suggestions?

25. Adding a day to the date

Ajay, That was very helpful, but sometimes the best way to teach is to point the student in the right direction and let him find the solution on his own. If Param had to code it himself, he would end up much more familiar with the methods of the Calendar class and how to use them. Scott

26. add periods to dates

Howdy "Cesar Tg.", You may not have noticed that we have a policy on screen names here at the ranch. It must consist of a first name, a space, and a last name. It must also not be fictitious. Unfortunately, your screen name does not seem to conform with this policy. Please take a moment to change it. Update... Our records ...

27. Adding weeks to a date

29. how to add monthS on date?

30. add a day to the date

31. adding no of days for given date

32. Adding date and time to a class?

Hi, I'm currently writing a number of classes to handle video loans etc. The current class, called 'Loans', handles simple information about a loan of a video to a borrower. My question is simply how do I add the date and time to this class so it is represented with the loan information for a borrower? My code for this class ...

33. Adding 'time' to a timestamp

import java.text.DateFormat; import java.text.ParseException; import java.util.Date; public class timstampDemo { public static void main(String[] args) { DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM); try { Date aDate = df.parse("00:00:59"); Date duration = df.parse("00:00:05"); Long milliDate = aDate.getTime(); Long milliDuration = duration.getTime(); Long milliNewDate = milliDate + milliDuration; Date newDate = new Date(milliNewDate); System.out.println(df.format(newDate)); } catch (ParseException ex) { ex.printStackTrace(); } } }

34. initialise & add date

35. add day to current date

36. Adding date

37. How to add Date to 1 more day?

38. add days to date

39. add 5 minutes to date

hi! i am trying to add 20 minutes to a date object like this: //this line actually comes as a parameter to the method Date time = Calendar.getInstance().getTime(); //here is the method code Calendar cal = Calendar.getInstance(); cal.setTime(time); logger.warn("time is " + cal.getTime()); cal.add(Calendar.MINUTE, globalObject.getSessionOut()); logger.warn("time plus 5 minutes is " + cal.getTime() + " current time is " + Calendar.getInstance().getTime()); ...

40. Set and add date

Hi, How can I use a static date attribute to store a specific date for example, 1/1/2008 using GregorianCalender class? Also, I need to add this date to the user's date when they enter day, month and year in integar. After all of this, I need to show the final date in the format day/month/year. Any help will be much appreciated. ...

41. Add Date Problem

42. What is the best way to add a day to a Date object?

I have come across numerous examples on adding a day to the CURRENT date, using the Calendar object. However, what I need to do is to add a day to a Date variable. Can someone tell me how to do that? I tried to set the value of my Date variable into the Calendar object, but, it appears that for the ...

43. add dates?

The date in the DataBase is stored in the form of TimeStamp (ie) the output comes in the form "2008-03-05 14:26:33.215" now this is not the current date and i need to add 30 days to this date. Is it possible. If so can you please send me the code for this. Thanks.

44. how to add 90 days to the system date

Do you realize that getInstance() is a static method of Calendar, not GregorianCalendar? Similarily, DAY_OF_YEAR is a static field of Calendar. So this code should be rewritten not to mention GregorianCalendar. Of course, depending on you locale, the object returned by getInstance could be an instance of GregorianCalendar, but then again, it could be an instance of the Thai Buddhist calendar, ...

45. can't add one to date

46. adding values to date

47. Adding dates in java

48. date.roll and date.add

Hello when I use Calendar cal = Calendar.geInstance(); cal.add(Calendar.DATE, -90); I can get what I want (roll back 90 days). But when I use Calendar cal = Calendar.geInstance(); cal.roll(Calendar.DATE, -90) I get then "now" plus three more days When I see Java API, I did not see the different between two functions(add and roll). Could you help me to know when ...

50. How to add 15 days to the current date

Hi everyone, I have the following doubt. I stored the current system date in to a variable.Now I want to store the date which is 15 days after the current date in to a new variable. ie current date:1-aug-09 later date:1-aug-09 + 15 days ie 16-aug-09. Plz help me in solving this problem. Thanks & Regards, srinivas

51. Wrong time when adding two dates

I know that it's a little abusive, to use the Date class like this, but I still don't get why it's not working. As you write darth_code_r, every date is represented like a number of milliseconds since epoch. So I have my m2 representing approx. 11 hours after epoch, and add it to a date (at midnight). Why is my final ...

52. adding to or subtracting from date object

This is working out well. Thank you for the joda mention. Only problem I have now is understanding the offset. I can see in my web service request that 2009-01-13T11:16:24.454Z But when it arrives to it's destination it becomes. The destination is on the west coast. 1/13/2009 6:12 AM give or take a minute or two. If I plusHours on the ...

53. How to add number of years to date

54. Adding 3 days to a Java Date

55. Adding new character to date format.

I want to give users a facility to view the quarters in which the date belongs to, embedded in itself. So, if the user specifies the format as "MMM/dd/yyyy/Q", then I want the output to be, "Jul/02/2008/4". I want to know, how do we allow the SimpleDateFormat to accept this new character "Q" and be able to apply it as the ...

56. Adding a date to a time range

Greetings to all, I really need help on this issue: Problem: Is possible to add the system date(dd/mm/yyyy) to a pre-existing time range? In my project, I have an appointment column which holds the value for a time range, e.g. 0900 - 1100hrs. How do I add the system date to this column so that the database would store the the ...

57. Adding days to date

58. Adding days to the current date

Honestly, I am not sophisticated enough to follow your last post. We really haven't covered anything like this in my class. These methods are < 5% of what the project calls for us to do in total and at least half of what we are expected to know is not covered by either the text book or the lectures. I don't ...

59. adding current_timestamp

Hi, I am currently trying to add a timestamp+(variable) to my mssql database via a JSP. I can add the simple time stamp by doing the following: ... PreparedStatement ps = connection.prepareStatement("INSERT INTO table1 VALUES (?,?,?, CURRENT_TIMESTAMP+5)"); ... ...which adds 5 days to the current date. However if i wanted to replace '5' with a variable how do i go about ...

60. Adding time issue using Date's getTime method

long msecSum = 0 ; DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS") ; try { Date date1 = dateFormat.parse("01:02:05.101") ; Date date2 = dateFormat.parse("02:03:10.102") ; System.out.println("Date1: " + dateFormat.format(date1)); System.out.println("Date2: " + dateFormat.format(date2)); msecSum = date1.getTime() + date2.getTime() ; // adds 5 hours !!! System.out.println("Sum: " + dateFormat.format(msecSum)) ; } catch (Exception e) { System.out.println("Unable to process time values"); }

62. adding minutes to date

i just want to add 30 minutes to the current date obtained as input so that i can put it ina loop to use it in a group by clause in oracle if sme one can help me out in identifying fuctions and classes in java api to do this easily it will be very help full waiting for it....................

63. Add date string to system.out's

I'm trying to add a time date string to all the System.out.println()'s which are being redirected to an output file. The code has tons of system.out.printlns and I'd like to avoid having to change each one to include the date and time. Any ideas or suggestions, greatly appreciated. (I'm redirecting with System.setOut(PrintStream) I'm thinking maybe I could extend printstream and add ...

64. adding date and time