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

Java Calendar TimeZone for US Stock Market

I am doing Android programming related to US NYSE & NASDAQ stock market. So far I know that they are using Eastern Time (ET). Stock market opens at 9.30AM ET, closes at 4pm ET. In order to check stock market is currently open / close, I want to…
Shuwn Yuan Tee
  • 5,578
  • 6
  • 28
  • 42
3
votes
4 answers

Java Calendar adds a random number of milliseconds?

Hi I have something weird happening. I am simply taking a calendar object, converting it to its individual parts, and putting it back into a calendar (with or without any changes. In this case I make no changes). I mean, this should be cut and…
StarWind0
  • 1,554
  • 2
  • 17
  • 46
3
votes
2 answers

Java Calendar bug?

After a lot of debugging I narrowed my problem to the following snippet: public static void calendarBug() { for (int i=0 ; i<6 ; i++) { Calendar c = Calendar.getInstance(); c.clear(); c.set(2015, 2, 27, i, 0); …
BioRoy
  • 375
  • 1
  • 3
  • 10
3
votes
3 answers

SimpleDateFormat incorrectly parsing string

String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss.SSSSSS"); Date d = f.parse(s); system.out.println(d); this is the code I am running it runs fine except when it prints it prints the time 19:17:46. Please someone explain…
2
votes
2 answers

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.HOUR_OF_DAY = " +…
2
votes
1 answer

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 of a week year may have different calendar year…
hiway
  • 3,906
  • 10
  • 34
  • 57
2
votes
1 answer

Is resultant java.time code has more code statements compared to equivalent Calendar code

Recently, I try to port one of our old code base, from Calendar to java.time, as we need quite a number of arithmetic functionalities, which is only found in java.time. If we use Calendar in our current code base, we need to perform a lot of…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
2
votes
3 answers

Determine how many days in a given month

I am doing some calculations based on no of days in a given month, Determine current Year Month Date date = new Date(); Year = YearFormat.format(date); Month = MonthFormat.format(date); Determine how many days in the current month int year =…
2
votes
1 answer

Calendar with no milliseconds vs Calendar with milliseconds that are 0

I cannot figure out how to tell if a Calendar object was created with no milliseconds versus a Calendar object that was created with milliseconds that happens to have a value 0. I need to distinguish between the time stamps 2018 04 30 13:44:55…
Brian Reinhold
  • 2,313
  • 3
  • 27
  • 46
2
votes
2 answers

Java Calendar.DAY_OF_WEEK gives wrong day

What is wrong with the below code? It gives wrong day for any date of the year. import java.util.Scanner; import java.util.Calendar; public class Solution { public static String getDay(String d, String m, String y) { String[] days =…
user3050866
  • 33
  • 1
  • 5
2
votes
1 answer

Calendar set date causing exception with message "Unparsable date"

My code to get the calendar date frone the string "2018-04-14'T'15:38:14", it is currently causing a exception WHEN i call setTime. The code Calendar cal = Calendar.getInstance(); // format of date yyyy-MM-dd'T'HH:mm:ss …
2
votes
2 answers

Arbitrary allocation of Java.Util.Calendar values

I am currently struggling with Java.Util.Calendar I have a method that creates a Calendar with random values for year, month and day. public Calendar getRandomGeburtstag() { int year = 1999 - (int) (Math.random() * 80); int month =…
Mindbomber
  • 21
  • 4
2
votes
0 answers

Performance issues with java.util.Calendar

I have the following code snippet as a part of a webservice - Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTime(date); calendar.set(Calendar.MILLISECOND, 0); …
2
votes
2 answers

Shift date an hour when in dst

I am processing a file line by line. Each line has a date in the following format: YYMMDD HHMM The file is basically recording a reading every 15 minutes. The recording is using day light savings for the time zone it is in. The issue I am having is…
DHines
  • 179
  • 1
  • 1
  • 9
2
votes
1 answer

How to check calendar value is null or empty in xhtml attribute

I have a column in my jsf page, i'm using primefaces dataTable: e.g:
zeeshan nazakat
  • 151
  • 3
  • 18
1
2
3
9 10