Forum : Date manipulations
Brief description  about Online courses   join in Online courses
View Jabira  Subrahmanyam 's Profile

Date manipulations

Can someone explain Date manipulations in java?
Asked by Jabira Subrahmanyam | Jun 28, 2010 |  Reply now
Replies (3)
View bhushan hanumant shinde 's Profile
to instantiate date, use the following "Date" constructor :-
Date

public Date(long date)
Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.
Parameters:
date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.

to print the date use "toString" method :-

toString

public String toString()
Formats a date in the date escape format yyyy-mm-dd.

for example:-

import java.util.Date;



class UsingDate {
public static void main(String[] args) {
long milliSeconds = 23232123123123l;
Date d = new Date(milliSeconds);

System.out.println(d.toString());
}
}

Sample output :-
Wed Mar 14 13:02:03 IST 2706
Jul 17, 2010
View jabira subrahmanyam 's Profile
How do we instantiate, how do we pass date in a method...
ex: print(Date date(){}); now when we call this function how do we pass parameters? print("12/12/2010");
Jul 1, 2010
View arun kumar das 's Profile
Please use date class in java.util package to manipulate date
Jun 29, 2010