util « Calendar « Java Data Type Q&A





1. Java.util.Calendar - milliseconds since Jan 1, 1970    stackoverflow.com

Program followed by output. Someone please explain to me why 10,000,000 milliseconds from Jan 1, 1970 is November 31, 1969. Well, someone please explain what's wrong with my assumption ...

2. How to specify firstDayOfWeek for java.util.Calendar using a JVM argument    stackoverflow.com

I'm trying to change default firstDayOfWeek for java.util.Calendar from SUNDAY to MONDAY. Is it possible to achieve this through JVM configuration instead of adding this piece of code?

cal.setFirstDayOfWeek(Calendar.MONDAY);

3. Why is the Java date API (java.util.Date, .Calendar) such a mess?    stackoverflow.com

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar) are a terrible mess. Off the top of my head:

  • Date ...

4. java.util.Calendar not reporting the correct timeInMillis    stackoverflow.com

findCalendarStart: time into Calendar: 1260575897

findCalendarStart: set hour : 13

findCalendarStart: after hour : 1249775897

findCalendarStart: after hour string: Thu Jan 15 11:09:35 UTC 1970

findCalendarStart: set minutes  : 13

findCalendarStart: after minutes: 1250015897

findCalendarStart: what ...

5. How to create a java.util.Calendar instance at epoch time?    stackoverflow.com

Is there any existing way to get a Calendar populated with time at epoch using Calendar API's other than explicitly setting them at epoch? All I was able to do was ...

6. How do I do calendar arithmetic with java.util.Date?    stackoverflow.com

Currently I have a Date object representing a time. How would I add 5 minutes to this object?

7. javascript implementation of java.util.calendar api    stackoverflow.com

Is there a javascript equivalent implementation of java.util.Calendar API? It will be quite handy to do date manipulation with it around.

8. Get java.util.Calendar from days since epoch    stackoverflow.com

I have a variable containing the days since epoch for a certain date. Does someone know the way to convert this variable to a java.util.Calendar?

9. Why doesn't java.util.Calendar make use of Enums?    stackoverflow.com

I sometimes get frustrated by the lack of type safety with j.u.Calendar and wondered if there was a good reason for not using enums in the Calendar API that has gone ...





10. Can java.util.Calendar be passed over method?    stackoverflow.com

this is my code:

import java.util.Calendar;

import java.util.Locale;

public class test {

    /**
     * @param args
     */
    public static void ...

11. how could i return an Islamic calendar using java.util.Calendar?    stackoverflow.com

I knew that java.util.Calendar class method getInstance() returns a GregorianCalendar but how could i get an Islamic calendar?

12. Question about java.util.Calendar    stackoverflow.com

I'm trying to understand the behavior with the following code. My local time zone is UTC -7 (Arizona).

Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE,40);
cal.set(Calendar.AM_PM,Calendar.PM);
System.out.println("1 UTC -4 Hour:" + cal.get(Calendar.HOUR_OF_DAY));
System.out.println("1 UTC -4 Day:" + cal.get(Calendar.DAY_OF_MONTH));
System.out.println("1 UTC ...

13. How to get date part (dispose of time part) from java.util.Date?    stackoverflow.com

I want to compare the date part of two java.util.Date objects. How do I could achieve this. I am not looking to comparing the date, month and year separately. Thanks in advance! ...

14. java.util.Calendar    coderanch.com

hi, i used Calender object to set valus .. calendar.set(year,month,day,hour,minute,second); i set year 2004 12 10...like that.. but after setting those values if i display them again the year value is changed to 2005 and month to 1(january).... and other values changed too. what is the reason for that ? need a help to get unchanged values form the calendar. thanks ...

15. Using java.util.Calendar    coderanch.com

16. Extending java.util.Calendar()    coderanch.com

Hi, I am trying to extend the Calendar(). Following is the code. import java.sql.Timestamp; public class Calendar extends java.util.Calendar{ public Calendar() { super(); System.out.println("Calendar after super(): " + super.getTime()); //if (AppMode.isTestMode() == true) if (true == true) { //java.util.Calendar cal = java.util.Calendar.getInstance(); super.setTime(new Timestamp(System.currentTimeMillis())); //Get the configured date from Application java.util.Calendar configuredCal = MyDate.getConfiguredCal(); super.set( configuredCal.get(Calendar.YEAR),configuredCal.get(Calendar.MONTH), configuredCal.get(Calendar.DATE)); } } } In ...





17. java.util.Calendar problem.    coderanch.com

How are you getting the timestamp from the database? >> I am not retrieving timestamp data from the database. I have access to database. So I am querying to know what is populated in Database field after I invoke the webservice. We are using thrid party application and, we don't have access to its code. I am invoking webservice in this ...

19. creating java.util.Calendar from time in seconds    coderanch.com

Hi Brunborg, Thank You for your response, long timeInMillis = 1995181298*1000; Calendar myCalendar = Calendar.getInstance(); myCalendar.setTimeInMillis(timeInMillis); Date theDate = myCalendar.getTime(); This is the exact piece of code i'm using to get the data & time for a given time in seconds. The following are input data and corresponding output i'm getting, 3159720303 Sat Feb 15 13:03:03 GMT-07:00 2070 3159720205 Sat Feb ...

20. Problem with java.util.Calendar.set(...)    coderanch.com

The following method is not returning the proper value for month. Did anyone face this problem? What is causing the Calendar Class to return wrong month? private String formatMonth(int m, Locale locale) { Calendar c = new GregorianCalendar(); c.set(Calendar.MONTH, m); DateFormat formatter = new SimpleDateFormat("MMMM", locale); System.out.println("FORMATMONTH =" + m + " ; Calendar.MONTH =" + Calendar.MONTH + " result = ...

21. java.util.Calendar bug on JDK6??    coderanch.com

22. java.util.Calendar    coderanch.com

23. Getting the maximum/min date java.util.Calendar can accomodate    coderanch.com

Thanks to everyone in advance - Coming from other languages such as PHP, the DateTime object has max and min dates that the respective object will allow. For instance PHP's DateTime is: $MinValue = "1901-12-13 20:45:54"; $MaxValue = "2038-01-19 03:14:07"; And C#: DateTime.MaxValue DateTime.MinValue I have played around with calendars getMinimum/getMaximum methods and here is what I come up with this ...

24. Java Calendar vs Java.util.Date    coderanch.com

Note that java.util.Date is not deprecated in general - but many (not all!) of the specific constructors are deprecated. I think of the relationship between these as similar to the relationship between String and StringBuilder (or StringBuffer). No, Date isn't immutable, but it should have been, and you should treat it as though it was. A Calendar is useful for building ...

25. Issue with java.util.Calendar in java1.5 & above    coderanch.com

Hi, I am facing issue while converting current date to Julian date in java 1.5 & above. I am using the below piece of code which is working fine in java 1.4. Is something wrong with logic or is it a know issue? String format="CCYYDDD"; StringBuffer julianDate = new StringBuffer(); GregorianCalendar gregCal = new GregorianCalendar(); //This particular line is making difference ...

26. Bug with java.util.Calendar    coderanch.com

can anyone tell me why I am getting Thursday as DAY_Of_Week for 2010-01-04 ( 4th January, 2010) when it was Monday that year? import java.util.Calendar; import java.util.GregorianCalendar; import static java.lang.System.out; public class MyCalendar{ private int year; private int month; private int dayOfMonth; public MyCalendar(int year,int month,int dayOfMonth){ this.year = year; this.month = month; this.dayOfMonth = dayOfMonth; } public MyCalendar(){ this.year = ...

27. Java.util.Calendar    coderanch.com

package com.manu.practice; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Timer { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Calendar calendar = new GregorianCalendar(); String am_pm; int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); if(calendar.get(Calendar.AM_PM) == 0) am_pm = "AM"; else am_pm = "PM"; System.out.println("Current Time : " ...

28. Is java.util.Calendar 's bug ?    forums.oracle.com

29. Working with java.util.Calendar    forums.oracle.com

Second question, Is it possible to parse date strings and not know the pattern before hand IE. specifying the pattern in the constructors of DateFormat/SimpleDateFormat. I will be working with dates that are randomly formatted and I cannot accomodate for each pattern. When I do not specify a pattern in the constructor and parse my dates, I get unparsable date exception ...

30. Bug in java.util.Calendar    forums.oracle.com

No one told you to comment out what you did and doing so makes absolutely no sense. If you want to create a new Calendar object and not make changes on another one, your way will fail. You must create a new object pure and simple, not set your temp object to refer to the parameter object.

32. Get the day on any particular date using Calendar class in java.util    forums.oracle.com

Hello friends Can any one tell me how do I get the day on any particular date using Calendar/Date class in java. example : If I set the date as follows Calendar c=Calendar.getInstance(); c.set(2004,11,14); Then I want the day on 14th Nov 2004. The day in the form of 1 for sunday 2 for monday etc etc Can any one help ...

33. Questions about java.util.Calendar    forums.oracle.com

Hi, I've hit a problem where java.util.Calendar is rejecting what appears to be a legitimate date. Here are the details: Calendar cal = Calendar.getInstance(); cal.setLenient(true); cal.clear(); cal.set(1942, Calendar.SEPTEMBER, 1, 0, 0, 0); cal.getTime(); When this code is executed on a machine in the India Timezone, I get an exception at cal.getTime(). I've investigated a little, and it is clear that the ...

34. java.util.calendar bug?    forums.oracle.com

Hello, I am having a problem with java.util.calendar. When I try to set the date for 5/31/2007 using the .set method, the get returns 6/1/2007. Other dates work fine. Any ideas would be greatly appreciated. My test code is pasted below: fCalendar.set(fCalendar.YEAR, 2007); fCalendar.set(fCalendar.MONTH, 05); fCalendar.set(fCalendar.DAY_OF_MONTH, 31); System.out.println("Date is " + fCalendar.get(fCalendar.MONTH) + "-" + fCalendar.get(fCalendar.DAY_OF_MONTH) + "-" + fCalendar.get(fCalendar.YEAR)); Result ...

35. java.util.Calendar bug?    forums.oracle.com

/** * Generates the filename of the output file. * * @return resulting value of the string. */ public static String generateOutputFilename() { String logDate = "2007-03-31"; String logTime = "9:59:59"; Calendar rightNow = Calendar.getInstance(); String year = Integer.toString(rightNow.get(Calendar.YEAR)); String month = Integer.toString(rightNow.get(Calendar.MONTH) ); String date = Integer.toString(rightNow.get(Calendar.DATE)); String hour = Integer.toString(rightNow.get(Calendar.HOUR_OF_DAY)); String minute = Integer.toString(rightNow.get(Calendar.MINUTE)); String second = Integer.toString(rightNow.get(Calendar.SECOND)); System.out.println("year ...

36. java.util.Calendar bug?    forums.oracle.com

37. First Tuesday of the month in java.util.Calendar?    forums.oracle.com

I'm trying to get the first Tuesday of the month using java.util.Calendar. There are some edge cases that I can't figure out how to handle without it feeling like a hack. For example, if I ask for TUESDAY in WEEK_OF_MONTH (or DAY_OF_WEEK_IN_MONTH, for that matter) where MONTH is set to NOVEMBER and year is set to 1996, I don't get November ...

38. using java.util.Calendar    forums.oracle.com

39. java.util.Calendar problem; need help asap plz    forums.oracle.com

hello. i have an application that depends on the java.util.Calendar. here is the code: Locale locales[ ] = Locale.getAvailableLocales( ); for ( Locale ll : locales ) { if ( ll.getDisplayCountry( ) != "" ) { Calendar cc = Calendar.getInstance( ll ); System.out.println( cc.getTimeZone( ).getDisplayName( )+"->" + ll.getDisplayCountry( ) ); } } basicly, the code looks through the locales, searches for ...