159 questions
2
votes
1
answer
156
views
Gregorian Calendar gets the wrong "start of the week"
This is August 2025:
August 2025
Mon Tue Wed Thu Fri Sat Sun
1 2 3
4 5 6 7 8 9 10
--> 11 12 13 14 15 (16) 17
18 19 ...
0
votes
2
answers
137
views
Calculate calender days between two dates in java
is there any way to calculate calendar days between two dates. I tried with below code but looks like it gives 1 day as answer. But I am expecting the difference between this date is 2 days. No need ...
-2
votes
1
answer
228
views
Subtract minutes from Date by using Calendar fails
I'm writing an app that must find some time for alarm (from Date object), and then should subtract several hours and minutes (by using Calendar object) selected by the user (interval, several hours ...
-1
votes
1
answer
158
views
java.util.Calendar returns Julian date instead of gregorian
I'm trying to get java.util.Calendar date field as following.
This is the DTO.
import java.util.Calendar;
public class ImportExportProgressDTO {
private Calendar prolongedDate;
}
public void ...
-2
votes
1
answer
79
views
Enter the year and the number of weeks, return the corresponding Monday start time,
The code looks like this:
LocalDate.of(year,1,1).with(WeekFields.of(Locale.ENGLISH).weekOfWeekBasedYear(),weekNumber).with(DayOfWeek.MONDAY)
But when I count 49 weeks for this year, which is 2023, ...
1
vote
0
answers
322
views
Android - Getting wrong TimeZone abbreviations? Understanding CET vs CEST
I would like to print the correct TimeZone abbreviation of a Date in Android but I'm a little confused.
As far as I know in the "Europe/Budapest" TimeZone we have "Standard Time" ...
0
votes
3
answers
160
views
using date for calender as an input to figure out the time difference
I have the following code and trying to figure out if the date difference is greater than one year or not. If I have the two dates like this:
2022-08-20 10:26:44.000
2023-08-25 10:26:44.000
How ...
0
votes
3
answers
2k
views
How to get Thisweek start and end date and Lastweek start and end date in Kotlin
I need to get this week startdate like 2023-02-20 and last week startdate and end date.
startdate will be monday.
so I create 4 variables like below.
private var thisWeekStart : Long = 0
private ...
1
vote
0
answers
117
views
Inconsistent behaviour of GregorianCalendar when created from ZonedDateTime
I'm writing some integration of legacy code that expects date/time as a GregorianCalendar.
So, I'm creating the GregorianCalendar using from(ZonedDateTime) method.
However, the result is showing some ...
0
votes
0
answers
56
views
How to set time and date in calender class in Java? [duplicate]
import java.util.*;
enum CITY{ROME,BUDAPEST,PARIS,GREECE,TALIN,AMSTREDAM,VIENNA;}
class Flight{
private String flightName = "AirBus";
private int ticketPrice = 50;
private CITY ...
0
votes
0
answers
201
views
online java compilers gives different results than eclipse and intelliJ
The code simply extract the time portion of two timestamps and sub them from each other to get the duration
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
...
1
vote
0
answers
33
views
addin days in provided date by user
String pickupdate = pdate.getText().toString().trim();
// String dateBefore = "25/10/2022";
// create instance of the SimpleDateFormat that matches the given date
...
0
votes
1
answer
59
views
Why this loop is infinity? [Java]
Why this code is an infinity loop? How I can fix it?
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
while (cal.SECOND < 20){
System.out.println(cal.SECOND);
}
Thanks you in ...
0
votes
2
answers
427
views
Trying to get Calendar data into a String
Trying to store data into a string.
This is my utilities.
public class CommonDatePicker {
public static void datePicker(final TextView textView, Context context) {
Calendar dateCalender = Calendar....
0
votes
1
answer
3k
views
How to compare if current time is greater than other time in Java?
I have a back-end job that runs once a day and is scheduled at a particular time based on the entity/user etc.
Now, I want to validate if the current time is earlier than the job, if yes, then job can ...
4
votes
2
answers
356
views
Java Calendar clear() changes DST
First, I want to state that I know the Java Calendar class is being supplanted by other libraries that are arguably better. Perhaps I've stumbled upon one of the reasons Calendar has fallen out of ...
0
votes
0
answers
127
views
Java Calendar Date [duplicate]
Calendar now = Calendar.getInstance();
System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1)
+ "-"
+ now.get(...
0
votes
2
answers
236
views
Crutch with the Calendar in Java
I'm writing an app for android. On the start of it I create a Calendar, filling such containers as YEAR, MONTH, DAY_OF_MONTH, ERA and time zone as GMT.
I get something like this
java.util....
0
votes
0
answers
716
views
Elastic Search - How to return records within time intervals
I have an elastic search db deployed within an AWS VPC. It holds millions of records all with a timestamp added based on the unix datestamp (new Date().getTime()). I am trying to pull (1) record per ...
1
vote
1
answer
2k
views
Parsing HTML date input into Timestamp in Java Servlet
Recently I'm having a problem with Timestamp and HTML input type Date:
This is my HTML/JSP:
<div class="form-group">
<label>Your day of birth</label>
<input class=&...
3
votes
1
answer
803
views
GregorianCalendar with a custom cutover date sets unexpected date before cutover
TL;DR: I'm getting a strange result when setting a GregorianCalendar with a custom Julian->Gregorian cutover date. 1 Jan 1800 becomes 12 Jan 1800, where 1800 is before the custom cutover date (31 ...
0
votes
2
answers
2k
views
How to get only date without time from calendar? [duplicate]
I use the following code to add one day to the calendar. However, I want to retrieve in a string only the date without the time. Is this somehow possible?
Calendar calendar = Calendar.getInstance();
...
-4
votes
3
answers
1k
views
What's the difference between Calendar.getInstance().get(Calendar.DAY_OF_WEEK) and Calander.DAY_OF_WEEK in java
I'm new to Kotlin and while doing a course there was a bit where you worked with the current weekday.
The course used this java code to get it:
import java.util.*
Calendar.getInstance().get(Calendar....
0
votes
3
answers
207
views
What am I generating when I generate a java Calendar object?
I am wondering how I should be using java Calendar objects in order to use them properly (use of this class is mandatory for my assignment so while I'd love to use some of the better options - they ...
0
votes
2
answers
196
views
calendar.getTime().equals(cal1) return false though both calendars has same time
Calendar calendar = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
if (calendar.getTime().equals(cal1.getTime())) {
System.out.println("Hi!");
}
...
2
votes
2
answers
975
views
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....
0
votes
1
answer
774
views
How to set a recurring holiday on the same date every year (disregarding the year component) with java using java.util.Calendar?
I am making a calendar that allows you to add a specific holiday which recurs each year automatically.
My WorkdayCalendar.class needs 2 methods:
-setHoliday(Calendar date) which sets a holiday only ...
1
vote
3
answers
227
views
How to add dates to calender in the right way
I have an ArrayList that contains date - [1, 5, 2020] // day|month|year
I am adding this to calendar in this way:
calendar.add(Calendar.DAY_OF_MONTH, dateList[0])
calendar.add(Calendar.MONTH, ...
0
votes
1
answer
347
views
Set method for Java Calendar only works if I do a print of it
I am facing a problem I really don't understand. I am trying to use the set method on a Calendar but it modifies the values only if I print it, here is the code:
Calendar cal = Calendar.getInstance();...
0
votes
3
answers
1k
views
How to Get first date and last date from given month in java? [duplicate]
We will pass month information in yyyyMM format.From that given input how i will get FirstDate and LastDate of that month?
Input:-202002
OutPut Should be:-
First Date:- 2020-02-01,
Last Date:- 2020-...
0
votes
3
answers
375
views
Convert Calendar set DAY_OF_WEEK to use TemporalAdjusters
I have some legacy code like this
final Calendar cal = new GregorianCalendar();
cal.setTime(today);
// changed on May-03-2004
//cal.set(Calendar.DAY_OF_WEEK, cal....
3
votes
1
answer
854
views
SimpleDateFormat week year
java8 GregorianCalendar DOC
A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days ...
0
votes
1
answer
82
views
Getting confused with java.util.Calendar
I want to get the date of SMS in format dd-MM-yyyy and time in format HH:MM (in 24hr format) on which it was received on phone. I use the following code
Calendar calendar = Calendar.getInstance();
...
0
votes
1
answer
444
views
Cannot create a Date object representing December 29, 2019
I hope it's not a JDK bug, or I am tempted to cash all my bank accounts and throw it in a mattress...
Here is the code. Please note that setting the date to Dec.29 immediately rolls the year to 2020. ...
0
votes
2
answers
1k
views
Calendar.getTime IllegalArgumentException [duplicate]
import java.util.Calendar;
public class WeekYear {
static String input = "202001";
//static String format = "YYYYMM";
public static void main(String[] args) throws ParseException {
...
-2
votes
4
answers
264
views
Why Calendar.after always retun true?
Hi can any one explain why such abnormal behavior from Calendar .after method
Calendar cal = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal.set(Calendar.HOUR, 14);
cal1.set(...
0
votes
2
answers
1k
views
Calendar.setTimeInMillis error - why is that? [duplicate]
calendar gets wrong unix time as I got.
long millis = 1568814839L;
System.out.println(millis); //1568814839
Calendar.getInstance(TimeZone.getTimeZone("Asia/Tashkent"));
calendar.setTimeInMillis(...
3
votes
1
answer
440
views
Is there any different behavior between Calendar#add(Calendar.MONTH, months) and LocalDate#plusMonth(months)?
I'm working on some legacy code where java.util.Calendar is used for date related calculations (basically adding months). Now I want to replace java.util.Calendar by java.time.LocalDate in the code ...
5
votes
0
answers
65
views
Is there anything in the java.time package that does the same thing as the roll method in java.util.Calendar? [duplicate]
I am currently ditching all usages of java.util Date implementations from my project and want to change everything to Classes from the java.time package.
Now I found a usage of the roll method of a ...
3
votes
2
answers
937
views
What is the equivalent of Calendar.roll in java.time?
I was studying the old Calendar API to see how bad it was, and I found out that Calendar has a roll method. Unlike the add method, roll does not change the values of bigger calendar fields.
For ...
0
votes
1
answer
292
views
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 ...
0
votes
1
answer
1k
views
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 ...
0
votes
3
answers
95
views
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 ...
2
votes
4
answers
11k
views
How add 30 days in current date? [duplicate]
I want to add 30 days in my current date I searched a lot but did not get the proper solution.
my code
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd");
Calendar ...
1
vote
3
answers
3k
views
I can't import java.util.date in activity
In my project I need to to use current date and time. For this I'm importing java.util.Date.
This import is working fine few hours ago. But I have an error in R file ( r cannot resolve ) and this ...
0
votes
0
answers
163
views
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?
...
-4
votes
1
answer
1k
views
Java Calendar getTimeInMillis() Returning the Same Time
I have a piece of code like this:
Calendar c = Calendar.getInstance();
long startTime = c.getTimeInMillis();
while (x < 10000000) {//check all the integers from 1 to 10000000 to
...
0
votes
1
answer
7k
views
Using Calendar in java. Getting a compilation error of cannot find symbol [duplicate]
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 ...
3
votes
1
answer
10k
views
How does Calender.set(Calender.Month, ?) Work? [duplicate]
I am writing a method that can advance the date by a given number of weeks. Here is my code:
public class Date {
int year;
int month;
int day;
public Date (int year, int month, int day){
this....
0
votes
1
answer
33
views
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 ...