Questions tagged [calendar]

A calendar is a system of reckoning time in which the beginning, length and divisions of a year are defined. The term may refer to a software class or library for the manipulation and display of calendar data, or to a list of events with associated dates and times, managed by a human via an application or operating system user interface.

Calendar in Primefaces:

Calendar is an input component used to select a date featuring display modes, paging, localization, ajax selection and more.

Value of the calendar should be a java.util.Date :

<p:calendar value="#{dateBean.date" />

public class DateBean{
   private date date;
}

Calendar in RichFaces :

The rich:calendar component allows you to select a date using a monthly calendar widget. It is possible to use the component in a popup or inline mode. In popup mode the calendar is initially rendered as an input for date with a button on the right side to trigger the popup.

<rich:calendar id="calendar" value="#{calendarBean.selectedDate}" />
13650 questions
389
votes
13 answers

Java Date vs Calendar

Could someone please advise the current "best practice" around Date and Calendar types. When writing new code, is it best to always favour Calendar over Date, or are there circumstances where Date is the more appropriate datatype?
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
372
votes
11 answers

Calendar Recurring/Repeating Events - Best Storage Method

I am building a custom events system, and if you have a repeating event that looks like this: Event A repeats every 4 days starting on March 3, 2011 or Event B repeats every 2 weeks on Tuesday starting on March 1, 2011 How can I store that in a…
Brandon
  • 16,382
  • 12
  • 55
  • 88
344
votes
18 answers

Why is January month 0 in Java Calendar?

In java.util.Calendar, January is defined as month 0, not month 1. Is there any specific reason to that ? I have seen many people getting confused about that...
Stéphane Bonniez
  • 4,577
  • 3
  • 21
  • 16
263
votes
8 answers

System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime()

In Java, what are the performance and resource implications of using System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime() As I understand it, System.currentTimeMillis() is the most efficient. However, in most…
Vihung
  • 12,947
  • 16
  • 64
  • 90
250
votes
17 answers

What's the best way to model recurring events in a calendar application?

I'm building a group calendar application that needs to support recurring events, but all the solutions I've come up with to handle these events seem like a hack. I can limit how far ahead one can look, and then generate all the events at once. Or I…
Clinton Dreisbach
  • 7,732
  • 6
  • 29
  • 27
234
votes
11 answers

Calendar date to yyyy-MM-dd format in java

How to convert calendar date to yyyy-MM-dd format. Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); Date date = cal.getTime(); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); String date1 =…
skmaran.nr.iras
  • 8,152
  • 28
  • 81
  • 116
231
votes
14 answers

How to get complete month name from DateTime

What is the proper way to get the complete name of month of a DateTime object? e.g. January, December. I am currently using: DateTime.Now.ToString("MMMMMMMMMMMMM"); I know it's not the correct way to do it.
user728885
225
votes
3 answers

Converting a Date object to a calendar object

So I get a date attribute from an incoming object in the form: Tue May 24 05:05:16 EDT 2011 I am writing a simple helper method to convert it to a calendar method, I was using the following code: public static Calendar DateToCalendar(Date date…
Will
  • 8,246
  • 16
  • 60
  • 92
218
votes
10 answers

How to subtract X day from a Date object in Java?

I want to do something like: Date date = new Date(); // current date date = date - 300; // substract 300 days from current date and I want to use this "date" How to do it?
yetAnotherSE
  • 3,178
  • 6
  • 26
  • 33
206
votes
8 answers

Convert String to Calendar Object in Java

I am new to Java, usually work with PHP. I am trying to convert this string: Mon Mar 14 16:02:37 GMT 2011 Into a Calendar Object so that I can easily pull the Year and Month like this: String yearAndMonth =…
Doug Molineux
  • 12,283
  • 25
  • 92
  • 144
200
votes
11 answers

How to subtract X days from a date using Java calendar?

Anyone know a simple way using Java calendar to subtract X days from a date? I have not been able to find any function which allows me to directly subtract X days from a date in Java. Can someone point me to the right direction?
fmsf
  • 36,317
  • 49
  • 147
  • 195
194
votes
8 answers

Java: Get month Integer from Date

How do I get the month as an integer from a Date object (java.util.Date)?
Muhd
  • 24,305
  • 22
  • 61
  • 78
193
votes
22 answers

Number of days in particular month of particular year?

How to know how many days has particular month of particular year? String date = "2010-01-19"; String[] ymd = date.split("-"); int year = Integer.parseInt(ymd[0]); int month = Integer.parseInt(ymd[1]); int day = Integer.parseInt(ymd[2]); Calendar…
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
184
votes
11 answers

Programmatically add custom event in the iPhone Calendar

Is there any way to add iCal event to the iPhone Calendar from the custom App?
Vadim
  • 9,383
  • 7
  • 36
  • 58
170
votes
28 answers

How do I calculate someone's age in Java?

I want to return an age in years as an int in a Java method. What I have now is the following where getBirthDate() returns a Date object (with the birth date ;-)): public int getAge() { long ageInMillis = new Date().getTime() -…
nojevive
  • 3,518
  • 3
  • 22
  • 18
1
2 3
99 100