How to get current timestamps in Java

Ads
 

How to get current timestamps in Java

Hi,

I want to get the current Timestamp in Java and then use it in JDBC program. How to get current timestamps in Java?

Thanks

View Answers

July 19, 2017 at 10:35 AM

Hi,

In Java using get the current Timestamp with the following code:

package net.roseindia;

import java.sql.Timestamp;
import java.util.Date;

/*
 * Example of getting current timestamp in Java 
 */
public class CurrentTimestamp {

    public static void main(String[] args) {
        //Using System current milliseconds
        Timestamp v1 = new Timestamp(System.currentTimeMillis());
        System.out.println(v1);

        //With the date object
        Date dt = new Date();
        Timestamp v2 = new Timestamp(dt.getTime());
        System.out.println(v2);

  }

}

First method is get the Timestamp using the:

System.currentTimeMillis()

function.

You can also also get it with the current Date.

    Date dt = new Date();
    Timestamp v2 = new Timestamp(dt.getTime());
    System.out.println(v2);

Thanks

Ads









Related Tutorials/Questions & Answers:
How to get current timestamps in Java
How to get current timestamps in Java  Hi, I want to get the current Timestamp in Java and then use it in JDBC program. How to get current timestamps in Java? Thanks   Hi, In Java using get the current Timestamp
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java and trying to write a program to get the current date. How to get the current date in Java? Thanks   Hi, Check the tutorial: Java program to get current date
Advertisements
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
Get current working directory in Java
Get current working directory in Java In this section we will discuss about how to get the the current working directory in java. Current working... to get current directory in Java with Example public class
How to get system current cursor type
How to get system current cursor type  In Windows how can i get the current mouse/keyboard cursor type like 'text cursor' from my java application
how to get current date without system date
how to get current date without system date  is there any possiblity to get current date instead of system date in Java, as i dont want to change date in program and if i change date in OS automatically change in program also
How to get current logged in Windows username? - Struts
How to get current logged in Windows username?  Can anyone give me the struts code to get the logged in Windows User name?  Hai srinath,  hai srinath, use the following statement in your particular servlet/jsp
Java program to get current date
Java program to get current date now       In this example program we have to get the current date at present now. We have used Calendar class for getting the current
How many ways can we get the value of current session id?
How many ways can we get the value of current session id?  How many ways can we get the value of current session id
How can we get second of the current time using date function?
How can we get second of the current time using date function?  How can we get second of the current time using date function
Java Example program to get the current working directory
Java Example program to get the current working directory... program illustrates to get the current working directory (CWD). With the File class object we can get two types of paths in java. These are as follows
How to get Java SDK
How to get Java SDK  Hi, I have purchased a new computer and installed windows 7. Now I have to get the Java SDK and install on my computer for developing and testing Java programs. So, can anyone tell me How to get Java SDK
JDBC: Get current Date and Time Example
JDBC: Get current Date and Time Example In this section, you will learn how to get current Date and current time using JDBC API. Get current Date and Time... in the format 'YYYY-MM-DD' You can get current date by writing 
how to get this xml syntx in java??????
how to get this xml syntx in java??????  how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
how to get this xml syntx in java??????
how to get this xml syntx in java??????   how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
Get current country from iPhone ??
Get current country from iPhone ??  hello, I want to get the current country in the iPhone settings. Can anyone tell me how to get the current... for NSLocale* current_Locale = [NSLocale currentLocale]; NSString* country
JDBC: Get current TimeStamp Example
JDBC: Get current TimeStamp Example In this tutorial, we are going to describe how to get current TIMESTAMP using JDBC API. Get current TimeStamp : CURRENT... object of Statement statement = con.createStatement(); // Get current
How to get enum value in Java
How to get enum value in Java  Hi all, i am looking for a solution to get an enum value from index in Java. Please suggest. Thanks
Get current page URL from backing bean
Get current page URL from backing bean  How to get current page URL from backing bean
How to get length of string in Java?
How to get length of string in Java?  What is the method of String for getting the length? How to get length of string in Java? Tell me code fast... Tutorials"; int length = str.length(); You have to use the str.length() to get
How to get day of week in Java?
How to get day of week in Java?  Hi, How to get day of week in Java? Thanks   Hi, Calendar class is very useful in Java. You can use this class for getting the day of the week. Here is sample code: int weekday
get current date in java in yyyy mm dd hh mm ss format
get current date in java in yyyy mm dd hh mm ss format  Hi, I want to get the current date into string yyyy mm dd hh mm ss format. How to get current date in java in yyyy mm dd hh mm ss format in a Java program? Thanks  
Java Get Month
and how to get the current date and time. But in this example, we are going to show the current month of the existing year. This Java get month example is simply... Java Get Month      
How to reload the current page?
How to reload the current page?  How to reload the current page
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
How to get UTF-8 working in java webapps?
How to get UTF-8 working in java webapps?  How to get UTF-8 working in java webapps
How to convert current date to dd mm yyyy format in Java?
How to convert current date to dd mm yyyy format in Java?  Hi, How to convert current date to dd mm yyyy format in Java? In my program I have to display the current date in the dd-mm-yyyy format to user on the website. How
How to convert current date to mm dd yyyy format in Java?
How to convert current date to mm dd yyyy format in Java?  Hi, How to convert current date to mm dd yyyy format in Java? Share me the program... for converting current date into MM-dd-yyyy format. Here is full code: package
how to get java path name
How to write script in Java  <html> <head> <script>alert('ok')</script> </head> </Html>
Getting the Current Working Directory in Java
C:\nisha>javac GetCurrentDir.java C:\nisha>java GetCurrentDir Current Working Directory : C:\nisha C:\nisha> Download this example

Ads