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

Selenium add weekdays to a date, weekend days not calculated correctly

I am running the below code on 6/7/2018 in order to omit weekends from any dates returned. However the code seems to determine the below days as the weekend. 13/7/2018 - Friday & 14/7/2018 - Saturday rather than 14/7/2018 - Saturday & 15/7/2018 -…
SteveL
  • 31
  • 3
1
vote
1 answer

Is there a way to use the GregorianCalendar on the JavaFX TableView?

Is there a way to have a column in the TableView show a proper date instead of: java.util.GregorianCalendar[time=?areFieldsSet=false... I want to know because it's irritating having it displayed like that on the Date column I have and having to…
1
vote
1 answer

How to get device Calendar (default calendar) events and display in our Application?

I am bit new to calendar. Can anybody suggest me how to get events (eg. birthday/meetings reminder) from default calendar (not google calendar or any other only default calendar) and display it in listview/recyclerview in our application?
Vikash Kumar
  • 395
  • 5
  • 17
1
vote
2 answers

Why is my Java Calendar.setTime() sporadically setting wrong times?

Using this code below, I noticed that sometimes the date gets formatted incorrecty. And to make it even more weird, sometimes timeStamp will have the right date, and timeStampCopy will have the wrong date, and visa versa. public static Timestamp…
1
vote
3 answers

Some doubts about Java polymorphism applied to the Calendar and GregoriaCalendar case

I have the following doubt. Into my code I have: Calendar today = Calendar.getInstance(); where today variable is an instance of Calendar so I can't use methods as isLeapYear() on it. Doing in this way I can perform this method: GregorianCalendar…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
1
vote
1 answer

Why GregorianCalendar sets HOUR depending on System time(AM/PM)

I am simply creating a java.util.GregorianCalender GregorianCalendar calender = new GregorianCalendar(); now setting the hour,min,sec and ms as follows c.set(Calendar.HOUR, 6); c.set(Calendar.MINUTE, 45); c.set(Calendar.SECOND, 30); …
Tanmoy Banerjee
  • 1,433
  • 3
  • 22
  • 31
1
vote
6 answers

How do I set a Calendar with TimeZone?

I have a timestamp that I am trying to put into a Date object, however when I use Calendar, I am running into a strange problem. I seem to be able to unable to create a Date object with the values I want: public static void main(String args[]){ …
xirt
  • 514
  • 1
  • 6
  • 18
1
vote
1 answer

Calendar: set TimeZone correctly

I would set a TimeZone for Calendar instance but i'm not able to do it. I've try with: DateFormat dateFormat = new SimpleDateFormat("dd//MM/yyyy HH:mm:ss"); Calendar cal =…
giozh
  • 9,868
  • 30
  • 102
  • 183
0
votes
3 answers

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 should I send these two dates such that it's…
Tan
  • 1,433
  • 5
  • 27
  • 47
0
votes
0 answers

Spring @ModelAttribute calendar type mismatch

I'm passing the date in formDate as ISO date string yyyy-mm-ddThh:mm:ss.uuuZ @PostMapping @ResponseStatus(HttpStatus.CREATED) public void create(@Valid @ModelAttribute PersonRequest request, BindingResult bindingResult) { for(…
galalem
  • 389
  • 11
0
votes
3 answers

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 var thisWeekEnd : Long = 0 private var…
Hyejung
  • 902
  • 1
  • 8
  • 22
0
votes
0 answers

How to set time and date in calender class in Java?

import java.util.*; enum CITY{ROME,BUDAPEST,PARIS,GREECE,TALIN,AMSTREDAM,VIENNA;} class Flight{ private String flightName = "AirBus"; private int ticketPrice = 50; private CITY Destination = CITY.ROME; private int…
0
votes
0 answers

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) { Calendar cal = Calendar.getInstance(); …
0
votes
1 answer

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 advance for yours help
rates336
  • 11
  • 1
  • 3
0
votes
2 answers

Trying to get Calendar data into a String [Solved]

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.getInstance(); final int year =…