A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_date.htm below:

Java Date Class

Java Date Class Introduction

The Java Util Date class represents a specific instant in time, with millisecond precision.

Class declaration

Following is the declaration for java.util.Date class −

public class Date
   extends Object
   implements Serializable, Cloneable, Comparable<Date>
Class constructors Sr.No. Constructor & Description 1

Date()

This constructor allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

2

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, 1970, 00:00:00 GMT.

Class methods Methods inherited

This class inherits methods from the following classes −

Creating a Date instance of current date Example

This Java example demonstrates the from() method of Date class to get Date instance of current time.

package com.tutorialspoint;

import java.time.Instant;

// Import the Date package
import java.util.Date;

// Main public class
public class DateDemo {
   public static void main(String[] args) {

      // create a date of current time
      Date date = Date.from(Instant.now());

      // print the date instance
      System.out.println("Date: " + date.toString());
   }
}
Output

Let us compile and run the above program, this will produce the following result −

Date: Mon Apr 01 10:20:08 IST 2024

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4