Date setTime(long) in Java

setTime(long): This method is available in java.util.Date class of Java.

Syntax:

void java.util.Date.setTime(long time)

This method takes one argument of type long as its parameter. This method sets this Date object to represent a point in time that is time milliseconds after January 1, 1970, 00:00:00 GMT. 

Parameters: One parameter is required for this method.

time: the number of milliseconds.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Date;

public class DatesetTime {
    public static void main(String[] args) {

        Date date = new Date();

        long time = 1881881999;
        date.setTime(time);

        System.out.println(date);

    }
}

Output:

Fri Jan 23 00:14:41 IST 1970


No comments:

Post a Comment