Calendar.setTimeInMillis()

Date

Calendar.setTimeInMillis(long value)Setting time by using UTC milliseconds from the epoch
Returns the new calendar object
Examples with output
We created on long type data and then used the same to assign setTimeInMillis for a calendar object.
package my_proj;
 
import java.util.Calendar;
 
public class my_first {
public static void main(String[] args) {
Calendar my_cal_d1 = Calendar.getInstance();// created calendar 
long my_time=1000000000;
System.out.println( my_cal_d1.getTime());
my_cal_d1.setTimeInMillis(my_time);
System.out.println( my_cal_d1.getTime());
}
}
Output
Thu Mar 05 15:17:39 IST 2020
Mon Jan 12 19:16:40 IST 1970
By using getTimeInMillis() we can get value in milliseconds.
package my_proj;
 
import java.util.Calendar;
 
public class my_first {
public static void main(String[] args) {
Calendar my_cal_d1 = Calendar.getInstance();// created calendar 
System.out.println( my_cal_d1.getTime());
System.out.println( my_cal_d1.getTimeInMillis());
long my_time2=my_cal_d1.getTimeInMillis();
my_cal_d1.setTimeInMillis(my_time2);
System.out.println( my_cal_d1.getTime());
}
}
Output
Thu Mar 05 15:04:10 IST 2020
1583400850686
Thu Mar 05 15:04:10 IST 2020
clear() Date & time tutorials



plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer