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

which is better for printing time in logs

I want to know whether new Date().toString or Calendar.getInstance().getTime().toString which is better since both give the same output and why choose one over the other? Scenario: I'm using them just to print time in logs so many in a Class many…
krrish0690
  • 51
  • 2
  • 11
-2
votes
2 answers

Two classes issue

I have asked you about GregorianCalendar and Calendar and some people said that Calendar is better. So I did it with Calender class. I have a problem with one method: JavaApplication1#whichIsEarlier(), always receives error. Please check it, if you…
dzoni
  • 21
  • 5
-3
votes
4 answers

Setting current date from ISO 8601 in object Calendar format using Java

Im trying to set the Calendar date object in the following way, but I don't know how. public void setTradeDate(String tradeDate) { Calendar tradeDate = ? } The String is in the format: String tradeDate = "2017-06-01T15:49:18Z";
Syed
  • 2,471
  • 10
  • 49
  • 89
-3
votes
2 answers

How to find due date from selected date?

I want to find due date from select date but it does't get. So please help me how to get due date. Here is my code below. Calendar date = Calendar.getInstance(); date.setTimeInMillis(date_in_mil); date.add(Calendar.DAY_OF_WEEK_IN_MONTH, 40); This…
-3
votes
1 answer

why factory method for creating Calendar Instance

Wanted to know more about Calendar.getInstance(). I can create Date instance with constroctor, but why not a Calendar instance? Why Calendar designed to use a factory method and why it has been abstract class. Please share the reason behind it. My…
Chowdappa
  • 1,580
  • 1
  • 15
  • 31
-4
votes
1 answer

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 //to see if they're prime or…
Kcits970
  • 640
  • 1
  • 5
  • 23
-4
votes
1 answer

I'm trying to get the date of monday before 1 of actual month

Java don't execute some lines of my code when I use Calendary library. I'm trying to get the date of monday before 1 of actual month. //Today is Tuesday, 2 January of 2019 (29/01/2019) Calendar cp1 =…
Hammerin87
  • 65
  • 1
  • 1
  • 8
-4
votes
2 answers

Why Calendar and SimpleDateFormat are showing a bad date?

I try to parse a date from a string but when I print it, it shows a bad date. My code: import java.util.Calendar; import java.util.GregorianCalendar; import java.text.SimpleDateFormat; public class Main { public static void main(String args[])…
Franco Morero
  • 549
  • 5
  • 20
-4
votes
2 answers

Why I obtain this error when I try to build a Java.utile.Date object from a String?

I am working on a Java application and I have some problem trying to create a Date object: So I have done: Calendar dataRendimentoLordoCertificatoCalendar = Calendar.getInstance(); dataRendimentoLordoCertificatoCalendar.set(annoCorrente - 1, 10,…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
-5
votes
3 answers

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.DAY_OF_WEEK) but I don't understand…
Gowther
  • 3
  • 2
-5
votes
2 answers

Why Calendar.SEPTEMBER is not working?

I want to see a month which contains whole days. private void createRandomData(InMemoryCursor cursor) { List data = new ArrayList<>(); Calendar today = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); …
BatuZ
  • 1
  • 4
-6
votes
1 answer

The method set(int, int) in the type Calendar is not applicable for the arguments (int, String)

Java code to create date from given day of week, week of month, month and year as input. Example- if the iputs are as below: day-Monday, month-july, week-1, year-2018, then output should be-02/07/2018. Below is the code used: …
Kirti
  • 31
  • 1
  • 10
1 2 3
9
10