An abstract class in Java that is used to convert an instance in time from Epoch to a specific date.
Questions tagged [java-calendar]
61 questions
9
votes
2 answers
How to compare objects of LocalDate and Calendar class?
I am trying to compare dates from two object having different types. Is there any way to convert Calendar object to LocalDater or vice-versa?
Thank you :)
public class ABC{
public static void main(String args[]){
Calendar c1=…

Maulik Doshi
- 323
- 2
- 11
6
votes
1 answer
What is difference between Java calendar vs Android calendar
I'm new to Android and I'm trying to get the current date but the Android Calendar class requires API 24. I need to support older device and the Time class is deprecated since API 22.
The problem is how to get current date on API 23 and I solved it…

Islam Assem
- 1,376
- 13
- 21
5
votes
3 answers
Get timezone of area with country code in Java
I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this:
System.out.println(TimeZone.getTimeZone("US"));
But its…

Manvi
- 1,136
- 2
- 18
- 41
3
votes
1 answer
Inaccuracy/randomness in java Calendar.toInstant() and Instant.atZone (also Local/ZonedDateTime.ofInstant())
I was developing a part of code where I had to use existing api using Calendar API where I was using purely new API. Got some strange behavior in the conversion, see this example:
SimpleDateFormat df = new…

domaru
- 348
- 2
- 13
3
votes
3 answers
Get week span as pair of zero-based day-of-year (0-364 or 0-365) numbers in Java
I need to get week span: start of week (Mo) | end of week (Sun) in days of year.
For example, for 5.9.2019, it should be 241-247 (days starting from 0).
However, my method produces 250 | 249
public static Pair getWeekSpan(Timestamp…

Talos
- 457
- 4
- 15
3
votes
1 answer
Java 8 Date API - Week of year is different for the same day but different time
For what I can only assume is a timezone issue, the following code yields different week of year values for the same day, but different times:
Note, the code is written in Kotlin
Example
fun main(args: Array) {
val…

Matthew Layton
- 39,871
- 52
- 185
- 313
2
votes
2 answers
Converting Date String to ZonedDateTime
I'm receiving a query parameter date, as yyyy-MM-DD (2022-03-08).
I want to conver this to java.util.Calendar / java.util.GregorianCalendar formmat.
So my idea is converto:
String -> ZonedDateTime -> Calendar.
What I did:
ZonedDateTime parsedDate =…

PlayHardGoPro
- 2,791
- 10
- 51
- 90
2
votes
2 answers
Java Calendar isn't showing correct HOUR_OF_DAY
I am using the Calendar class in java and am having trouble. I have this code
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("NZST"));
System.out.println("Calendar.HOUR_OF_DAY = " +…

Simon Mitchell
- 85
- 7
2
votes
2 answers
Print 12 Month Year and the next 2 Years using Java
Already had an initial program for this one, I made the code as much shorter and precise as possible. But upon checking it seems that the next 2 years still prints 2018 and I am expecting 2019 and 2020. How can I possible dynamically prints the year…

遊星不動
- 25
- 4
2
votes
2 answers
Setting values in calendar (java.util.Calendar)
I'm learning the Calendar class in Java and I am unable to understand the Set(Calendar.Day OF MONTH) method.
Here it goes:
import java.util.Calendar;
import java.util.Date
public class TestCalender
{
public static void main(String[] args)
…

Roopa
- 23
- 5
2
votes
1 answer
Android Calendar getFirstDayOfWeek bug
I want to get the first day of the week but I have a strange bug.
If I use this code:
Calendar cal = Calendar.getInstance();
cal.set(2017, 0, 1);
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
DateFormat dateFormat =…

Louis
- 406
- 6
- 13
1
vote
1 answer
java.util.Calendar not updating the timezone properly
The goal of this method is to take a utc date, convert it to the timezone specified and return the DateTimeValue object. However we recently found a bug with this method when using it with certain timezones.
private static DateTimeValue…

owen gerig
- 6,165
- 6
- 52
- 91
1
vote
1 answer
How to get previous/last Saturday for a given date in Java?
For example:-
String fromDate="09/18/2020";
I want my actual fromDate to be last Saturday that is "09/12/2020" .
Another example:-
String fromDate="09/01/2020";
I want my actual fromDate to be last Saturday that is "08/29/2020" .

Lina
- 31
- 5
1
vote
1 answer
Changing the Session Languge leads to "java.text.ParseException: Unparseable date
whenever I'm defining the timeframe being in German session language after changing to English lang. session (and vice versa) I'm getting the:
java.text.ParseException: Unparseable date: "10.10.2018"
Here is the fragment:
Date startDateFormatted…

alexandru catanet
- 89
- 3
- 9
1
vote
1 answer
how can you combine date and sql time into a single date time in java?
Using java Calendar how can you combine the start date, day and starttime?
For example:
If the start date is 9/8/2020. The day is 2 and the start time is 8:00 AM then how can we obtain a java date that is 9/9/2020 8:00 AM. Here is my unsuccessful…

kofhearts
- 3,607
- 8
- 46
- 79