Make a java.sql.Timestamp Object for a Given Year, Month, Day, Hour : Date Time Timestamp « Database « Java Tutorial

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
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Database » Date Time Timestamp 
20. 20. 20. Make a java.sql.Timestamp Object for a Given Year, Month, Day, Hour
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class MainClass {
  public static void main(String[] a) {

    System.out.println(makeTimestamp(2002,02,02,02,02,02,02));
  }

  public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute,
      int second, int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
  }

}
2002-02-02 02:02:02.002
20. 20. Date Time Timestamp
20. 20. 1. Working with Date, Time, and Timestamp in JDBC
20. 20. 2. Insert Date value
20. 20. 3. Get Date value from ResultSet
20. 20. 4. Insert TIME value
20. 20. 5. Get TIME value from ResultSet
20. 20. 6. Insert TIMESTAMP value
20. 20. 7. Get TIMESTAMP value from ResultSet
20. 20. 8. Get the Current Date as a java.util.Date Object
20. 20. 9. Creating java.sql.Date Using java.util.Date
20. 20. 10. Creating java.sql.Date Using java.util.Calendar
20. 20. 11. Creating java.sql.Date Using the java.sql.Date.valueOf() Method
20. 20. 12. Creating java.sql.Date Using GregorianCalendar
20. 20. 13. Getting a Timestamp Object Using java.util.Date
20. 20. 14. Getting a Timestamp Object Using System.currentTimeMillis()
20. 20. 15. Get the Current Timestamp as a java.sql.Time Object?
20. 20. 16. Convert a String Date Such as 2003/01/10 to a java.sql.Date Object?
20. 20. 17. Convert a Timestamp to Month-Day-Year
20. 20. 18. Get a Date Label from a java.sql.Timestamp Object
20. 20. 19. Convert a java.sql.Timestamp Object to a java.util.Date Object?
20. 20. 20. Make a java.sql.Timestamp Object for a Given Year, Month, Day, Hour
20. 20. 21. Get a Date for a Specific Time Zone
20. 20. 22. Returns a java.sql.Timestamp equal to the current time
20. 20. 23. Convert into java.sql.Time into java.util.Calendar
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.