Questions tagged [java.util.calendar]

The Java class for converting a moment in time (java.util.Date) to fields that represent the date (day, hour, minute, etc.).

The java.util.Calendar class has existed since Java 1.1. It allows conversion between the Date interpretation of "number of milliseconds" since midnight, January 1, 1970 UTC to fields such as year, month, day, hour, minutes, seconds, and milliseconds. These fields are mutable.

147 questions
0
votes
3 answers

Incorrect data returned by Calendar API

In our business requirement we are supposed to find out the first day of the week. Since the client is European so I used following code to get it. But, issue is when I run this code I am getting 2 as the answer where as I am expecting 1. public…
T-Bag
  • 10,916
  • 3
  • 54
  • 118
0
votes
2 answers

Different/Incorrect results in calendar field

I'm trying to add event but it shows a different date that I'm trying to put and what I'm getting. eventButton.setOnClickListener( new Button.OnClickListener() { @Override public void onClick(View v) { …
CoDesign
  • 43
  • 1
  • 8
0
votes
2 answers

calendar start date before end date on same day difference

I have two calendar dates where i am getting the difference between in days, hours, and minutes. This works perfectly if the end date is greater than the start date. What doesnt work is if the start date is the same day of week as the end date, but…
user7367398
0
votes
5 answers

Calendar minute not giving the right minute

The code below shows the text of a parsed Date object, and the static field Calendar.MINUTE. Can someone inform why they're different? The docs say it's supposed to get the current minute value as an int. EDIT: image removed, code/result…
juju
  • 553
  • 1
  • 4
  • 21
0
votes
2 answers

Unexpected result subtracting 24 hours from date 03/25/2018

I am subtracting 24 hours from a GregorianCalendar 03/25/2018 09:41. Result 03/24/2018 08:41. public class Utiles{ public static void main(String args[]) { SimpleDateFormat sdt = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); …
0
votes
2 answers

Calendar.set not changing Calendar variables

I've been working on a program for my Computer Programming class and I'm having a little trouble. Truthfully, I'm on the verge of insanity... Its a calendar program and the part I'm having trouble with is the Calendar object in java. Here is my code…
0
votes
2 answers

Day Light Saving Issue with Java Calendar

This is regarding Java Calendar and the effects we encountered after today day light saving change in Toronto. Below is the code Date date = new Date(); //Sun Mar 11 00:00:00 EST 2018 Integer time = 349; Calendar scheduleDateCal =…
keth
  • 793
  • 2
  • 11
  • 36
0
votes
2 answers

GregorianCalendar gives wrong day number

I've the below code, where I'm trying to post a sales order transaction, with date and qty, once I', getting the day of the transaction date, it is lagging 31 days, and apparently the Dec 1st is considered to be day number 1 in he year!! Anything…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
2 answers

Adding seconds to a Calendar object using Calendar.MINUTE add method

Can we pass a long value in Java such that it adds only seconds in the following code: Calendar calendar= Calendar.getInstance(); calendar.add(Calendar.MINUTE, (int) **SomeLongValue**); Where SomeLongValue adds only seconds to the calendar…
Palak
  • 25
  • 1
  • 1
  • 8
0
votes
1 answer

GregorianCalendar field not being converted to Date through TypeConverter

My TypeConverter is not working for converting GregorianCalendar to an sql Date type. An error is being thrown on the following code: /** due date of item */ @TypeConverters({CalendarConverter.class}) private GregorianCalendar dueDate =…
0
votes
0 answers

Strange java.util.Calendar behavior in API Level 23 and downwards

When working with java.util.Calendar on Android, I stumbled upon an interesting bug: on API level 23 or lower some fields set by Calendar.set(...) won't be applied until Calendar.get(...) is called (as the get-method internally calls complete()…
CodeX
  • 48
  • 6
0
votes
4 answers

Setting Calendar fields in Android

setting the day field in a calendar using myCalender.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); does is put set the day to the next Friday or the past Friday or maybe the closest? Also what if I don't set the year or any other field for the…
0
votes
1 answer

date time set to calendar with specific time zone not giving correct convert date time of other time zone in java

Here I am giving parameters like month, date, hourofday, seconds like(2,14,11,0), first setting zonevalue (IST). Calendar localTime = Calendar.getInstance(); localTime.setTimeZone(TimeZone.getTimeZone(zoneValue)); localTime.set(2018,…
0
votes
1 answer

How to prevent calendar event collision?

I'm using alamkanak/Android-Week-View library and works fine, but I want to prevent this to happen: I try this: Calendar oldEndTime = null; Calendar oldStartTime = null; for (int i = 0; i < mNewEvents.size(); i++) { …
0
votes
2 answers

Calendars getTime method modifies the timezone

I have a problem whereby the Calendar.getTime() method changes the timezone (probably to be in line with the JVM). Calendar cal = javax.xml.bind.DatatypeConverter.parseDateTime("2017-10-20T07:10:08.123458Z"); Date datrFromCal = cal.getTime();//Adds…