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
1 answer

I'm facing an error with jcalender code in netbeans

I'm making an airplane reservation system with java and when I run the code, it results into an error. The error I'm receiving is: "Incompatible types: Date cannot be converted into calendar." And it appears at…
user10620371
0
votes
1 answer

java.time.ZonedDateTime Vs java.util.Calendar performance check

I was trying to get month value. But I wanted to check which is better, java.util or java.time to retrieve month value. This is my code to check performance of Calender vs ZonedDateTime. //import java.time.Instant; //import…
0
votes
3 answers

Calendar work in all the year except in July

I have an app that use a calendar and I need to take the day of week. The problem is that it takes the correct day of week in all the dates around the year, except in July. I tried to add differents dates around all the year, but this problem only…
Abraham
  • 189
  • 1
  • 18
0
votes
0 answers

Efficient Way to Convert Calendar instance to java.sql.Timestamp

I am converting the Calendar instance result.submissionDate to java.sql.Timestamp as below, am wondering is there any alternative efficient way to do this by avoiding creating new Timestamp object? invoice.setSubmittedAt(new…
OTUser
  • 3,788
  • 19
  • 69
  • 127
0
votes
1 answer

Using Calendar in java. Getting a compilation error of cannot find symbol

I am getting error for cannot find symbol getInstance(),Calendar.DATE,Calendar.MONTH,Calendar.YEAR This only occurs when I am running offline on VS Code. On running in on an online IDE (Hacker Rank), I get compilation successful. JDK 11 on…
Nuruddin
  • 23
  • 2
  • 7
0
votes
1 answer

Need to query Calendar instance for Calendar setting to work

I have a Calendar instance that starts with the first day in December. I am trying to set that Calendar instance to the last Tuesday of the year. Somewhere between setting the last day of the year and the day of week, the Calendar instance reverts…
Baracus
  • 580
  • 7
  • 15
0
votes
1 answer

Calendar date is different

Why does Calendar in Android give different dates on different Android devices? I did get the default locale and still I have the same problem. Code: calendar = Calendar.getInstance(); currentDate =…
Mahmoud Ashour
  • 327
  • 4
  • 11
0
votes
0 answers

Calendar.getTime returns incorrect date

I have a JCalendar propertyChangeListener in which I am getting the new selected date using Calendar newValue = (Calendar) evt.getNewValue(). In cases when the old date is 31 and new selected month is one of the 30 days month, when I try to get the…
0
votes
1 answer

Change in Calendar date by default

I am having a strange problem here in android project. I am trying to convert the date into other date and for that, I am calculating the days between two dates. So, here is how I have implemented. Calendar baseEngDate = new…
0
votes
2 answers

Java: GregorianCalendar Strange Output

I am new to Java and I am trying to get the yesterday date with the following code: GregorianCalendar gc = new GregorianCalendar(2018,9,22);//<-Today gc.add(gc.DATE, -1);//<-Yesterday SimpleDateFormat dateFormatter = new…
3AKOBAH
  • 105
  • 6
0
votes
1 answer

Why calendar.add() return 31/9/2018

I want add 2 days from today (29/9/2018), i use: val calendar = Calendar.getInstance()!! calendar.set(CalendarDay.today().year, CalendarDay.today().month+1, CalendarDay.today().day) calendar.add(Calendar.DAY_OF_MONTH, 2) But when i Log() it, date…
mducc
  • 743
  • 1
  • 9
  • 32
0
votes
5 answers

How can I compare hours?

I am building an app, and I need to know how to compare two hours. For example, my store opens at 6:30 AM and closes at 5:00 PM. I need to show in a TextView that after 5 PM my store is closed, and after 6:30 AM my store is open, from Monday to…
Matt
  • 39
  • 1
  • 6
0
votes
4 answers

Convert java Calendar object from local time to UTC

How do I convert a Java Calendar object from local time to UTC? This what I have tried: Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTime(localDateTime.getTime()); …
Phil O
  • 1,588
  • 4
  • 28
  • 52
0
votes
1 answer

Calendar returns wrong week

So I need to get time in milliseconds for Monday of this week and time in milliseconds of Sunday for this week and with code below it worked fine till I installed app on emulator and if I set time to Sunday it returns Jun 18 - Jun 24, but on Samsung…
LeTadas
  • 3,436
  • 9
  • 33
  • 65
0
votes
2 answers

Calendar returns bad start of week on some Android devices

I wanted to get the date of first day in current week. So I implemented it in this way: fun getFirstDayInCurrentWeek(): Date { val calendar = Calendar.getInstance() calendar.clear(MILLISECOND) calendar.clear(SECOND) …
Nominalista
  • 4,632
  • 11
  • 43
  • 102