Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Java.util packages
Date
● The java.util.Date class represents a specific
instant in time, with millisecond precision.
● Most of the methods i...
Constructors in java
Constructor Description
Date() This constructor allocates a date object
and initializes it so that it...
Methods in Date class
Method Description
Boolean after(Date when) This method tests if this date is after the
specified da...
Cont'd
Methods Description
String toString() This method converts this Date object to
string of the form
Date format codes
Sample code for Date
package day5;
import java.util.Date;
public class DateClass
{
public static void main(String[] args)
...
Code for comparing dates
Sample output
Parsing string to date
Sample output
Any queries?
Thank you
Upcoming SlideShare
Loading in …5
×

Date class

310 views

Published on

introduction to Date classes in java

  • Be the first to comment

  • Be the first to like this

Date class

  1. 1. Java.util packages
  2. 2. Date ● The java.util.Date class represents a specific instant in time, with millisecond precision. ● Most of the methods in the class are deprecated in favor of the java.util.Calendar class. ● Date d = new Date();
  3. 3. Constructors in java Constructor Description Date() This constructor allocates a date object and initializes it so that it represents the time at which was allocated, measured to the nearest milliseconds Date(long date) This constructor allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as “the epoch”, namely january 1,1940, 00:00:00 GMT
  4. 4. Methods in Date class Method Description Boolean after(Date when) This method tests if this date is after the specified date Boolean before(Date when) This method tests if this date is before the specified date Object clone() This method return a copy of this object. Int compareTo(date anotherDate) This method compares two dates for ordering Boolean equals(object obj) This method compares two dates for equality Long getTime() This method returns the number of milliseconds since january 1, 1970, 00:00:00 GMT represneted by this Date object. Int hasCode() This method returns a hash code value for this object Void setTime(long time) This method sets this Date object to represent a point in time that is time milliseconds after january 1, 1970
  5. 5. Cont'd Methods Description String toString() This method converts this Date object to string of the form
  6. 6. Date format codes
  7. 7. Sample code for Date package day5; import java.util.Date; public class DateClass { public static void main(String[] args) { Date d = new Date(); System.out.println(d); } } Output : Tue Jul 01 11:30:18 IST 2014
  8. 8. Code for comparing dates
  9. 9. Sample output
  10. 10. Parsing string to date
  11. 11. Sample output
  12. 12. Any queries?
  13. 13. Thank you

×