Create instance of java.sql.Date from Calendar.getTimeInMillis() : Calendar « Data Type « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Data Type » Calendar 




import java.util.Calendar;

public class Main {
  public static void main(String[] args) {
    int year = 2009;
    int month = 0// January
    int date = 1;

    Calendar cal = Calendar.getInstance();
    cal.clear();

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);

    java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis());
    System.out.println(sqlDate);
  }
}
//2009-01-01














2.39.Calendar
2.39.1.The java.util.Calendar Class
2.39.2.Create instance of java.sql.Date from Calendar.getTimeInMillis()
2.39.3.Create a Date object using the Calendar class
2.39.4.Using the Calendar Class to Display Current Time in Different Time Zones
2.39.5.Get day of week
2.39.6.Display Day of Week using Java Calendar
2.39.7.Display Month of year using Java Calendar
2.39.8.Get current date, year and month
2.39.9.Get current time information
2.39.10.Get the last date of a month
2.39.11.Get the last day of a month
2.39.12.Display full date time
2.39.13.Get time in milliseconds using Java Calendar
2.39.14.Get Week of month and year using Java Calendar
2.39.15.Construct a Calendar object by using the setTime method
2.39.16.To obtain a date part, such as the hour, the month, or the year, use the get method
2.39.17.To change a date/time component, use its set method: public void set (int field, int value)
2.39.18.Change multiple components at the same time
2.39.19.Check for a Leap Year
2.39.20.Checking for a Leap Year: using GregorianCalendar
2.39.21.Get Days Of The Week for different locale
2.39.22.Get the number of days in that month
2.39.23.Try month in a leap year
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.