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
2
votes
2 answers

How to get the date of next specified day of week

I have to calculate the next date based on the current date. For example, say today is '05-NOV-2014' and user have gave an input like 1st Monday. so based on the user input if the 1st Monday of the current month has already gone past then i have to…
Shibankar
  • 806
  • 3
  • 16
  • 40
2
votes
1 answer

Minimal Days In First Week of the Year in Java

I am actually going through the utility class Calender. I find myself confused with, The methods getFirstDayOfWeek() returns the first day of the week; e.g., SUNDAY in the U.S., MONDAY in France. and getMinimalDaysInFirstWeek() returns the…
Farhan stands with Palestine
  • 13,890
  • 13
  • 58
  • 105
2
votes
1 answer

converting XMLGregorianCalendar object in String format to XMLGregorianCalendar object again

I have converted an XMLGregorianCalendar object to String using toString() method. So in a String variable I have "2014-09-02T10:55:58.000+05:30" . Now I want to load this value to an XMLGregorianCalendar object again. GregorianCalendar cal = new…
sayan
  • 501
  • 2
  • 7
  • 21
2
votes
1 answer

Java/Android Calendar, add 1 week on Sundays

OK, so my code has worked good until the day became Sunday. I'm working on an app that uses the Calendar util allot, so it functioning the way i think it does is important to me! The problem: import java.util.Calendar; ... Calendar…
user1004147
  • 315
  • 1
  • 2
  • 10
2
votes
3 answers

Do i need to change the date along with the timezone

I have a Calendar object [ localDate ] which is in EST : say Nov 6, 15:34... and i set the timeZone to GMT+5:30... Now when i do the Calendar.HOUR_OF_DAY it returns me 2... which i know is perfect.. since its 15:34 + 5 hrs to GMT and then +5:30 to…
Roshan Khandelwal
  • 953
  • 1
  • 11
  • 17
1
vote
0 answers

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 inconsistent behaviour when the GregorianCalendar…
1
vote
0 answers

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 SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); …
1
vote
1 answer

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:
1
vote
3 answers

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, dateList[1]) calendar.add(Calendar.YEAR,…
1
vote
4 answers

How add 30 days in current date?

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 c1 = Calendar.getInstance(); String currentdate =…
A.J
  • 133
  • 1
  • 1
  • 11
1
vote
3 answers

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 error is because of some xml mistake. When I…
1
vote
1 answer

How can I change the Calendar Offset?

I need to change Calendar timezone offset I tried many thing; 1- Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(TimeUnit.HOURS.convert(rawOffset, TimeUnit.MILLISECONDS) + System.currentTimeMillis()); 2- TimeZone timezone =…
1
vote
2 answers

Strange behavior of the java.util.GregorianCalendar class in different android versions

I am creating a calendar in my Android application. The first day of the calendar is Sunday or Monday. It depends on the locale. Strange behavior of the java.util.GregorianCalendar class in different android versions: public class CurrentMonth…
1
vote
0 answers

Android DatePickerDialog creates random wrong month

When I implement a DatePickerDialog it display the correct date but when I click OK to set the date in an EditText I get a date String with incorrect month, which seems to be random each time I try final Calendar calendar =…
1
vote
1 answer

Calendar set() broken on Android API 23 and below - java.util.Calendar

I am using java.util.Calendar to find the start of a given week using its set() methods. This works perfectly on Android Nougat+, but not on any Android version below Marshmallow. I have tested on both physical devices and emulators. I have used…
1 2
3
9 10