Skip to content
Advertisement

Tag: calendar

calculate number of weeks in a given year

I would like to get the number of weeks in any given year. Even though 52 is accepted as a generalised worldwide answer, the calendars for 2015, 2020 and 2026 actually have 53 weeks. Is there any way that I can calculate this, or any functions that will help me out? Answer According to the wikipedia article on ISO week

In Java, what is the fastest way to get the system time?

I’m developing a system that often use the system time because the Delayed interface. What is fastet way to get the time from system? Currently I’m using Calendar.getInstance().getTimeInMillis() every time I need to get the time, but I don’t know if there is a faster way. Answer System.currentTimeMillis() “Returns the current time in milliseconds”. Use this to get the actual

How to sanity check a date in Java

I find it curious that the most obvious way to create Date objects in Java has been deprecated and appears to have been “substituted” with a not so obvious to use lenient calendar. How do you check that a date, given as a combination of day, month, and year, is a valid date? For instance, 2008-02-31 (as in yyyy-mm-dd) would

How to convert a date String to a Date or Calendar object?

I have a String representation of a date that I need to create a Date or Calendar object from. I’ve looked through Date and Calendar APIs but haven’t found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution? Answer In brief: See SimpleDateFormat

Advertisement