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

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 be rescheduled, else if job has already passed,…
nick235
  • 7
  • 5
0
votes
0 answers

Java Calendar Date

Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" …
Sunil S R
  • 11
  • 1
0
votes
2 answers

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…
0
votes
0 answers

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 time slot based on min/max hour and minute…
0
votes
2 answers

How to get only date without time from calendar?

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(); calendar.setTime(new Date()); …
stefanosn
  • 3,264
  • 10
  • 53
  • 79
0
votes
3 answers

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 aren't options). I've read the documentation here:…
user-kk-
  • 11
  • 2
0
votes
2 answers

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!"); } Printing calendar.getTime() and cal1.getTime() returns Mon…
Hemlata
  • 367
  • 1
  • 3
  • 13
0
votes
1 answer

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 within that year -setRecurringHoliday(Calendar…
0
votes
1 answer

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(); cal.set(2020,2,31); //…
0
votes
3 answers

How to Get first date and last date from given month in java?

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-02-29 DateFormat dateFormat = new…
Tarik
  • 139
  • 1
  • 12
0
votes
3 answers

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.getFirstDayOfWeek()); if…
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
0
votes
1 answer

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 =…
0
votes
1 answer

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. Also, the toString() output reveals that…
0
votes
2 answers

Calendar.getTime IllegalArgumentException

import java.util.Calendar; public class WeekYear { static String input = "202001"; //static String format = "YYYYMM"; public static void main(String[] args) throws ParseException { Calendar lCal = Calendar.getInstance(); …
0
votes
2 answers

Calendar.setTimeInMillis error - why is that?

calendar gets wrong unix time as I got. long millis = 1568814839L; System.out.println(millis);…