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 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
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"/>
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
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 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
how to get browser cookies in java
how to get browser cookies in java  Hi, How to get cookies in serverlet and then print? how to get browser cookies in java? Thanks   Hi, Use following code: Cookie[] cookies = request.getCookies(); for (int i = 0
how to get file extension in java
how to get file extension in java  Hi, I want to get the file extension in Java. how to get file extension in java? Thanks   Hi, Here is sample code to get file extension in Java: package examples; import
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  
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
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
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 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>
java how to get domain name from url
java how to get domain name from url  How to get the domain name from a url string? Example program in java for "how to get domain name from url" Thanks   Hi, You can use the following example code: URL linkURL
How to get the unicode of japanese character input in java
How to get the unicode of japanese character input in java  Good Evening sir/madam; I am trying to create an application in java which needs to show the japanese character on frame and need to get the japanese string from
how to get session object in simple java class??
how to get session object in simple java class??  i am fallowing... into session. so, please tell me, how to get the session object (GroupPojo) in a simple...) GroupDetailsDao.java (it is also a simple java class which have the jdbc logic
Get current Date and Time
Get current Date and Time In this section we will discuss about how to get current date and time in java. Java provide two classes, Date and calendar which will display the current date and time in java. SimpleDateFormat is used 
How to print current time in r?
How to print current time in r?  Hi, I am learning and want to print current date and time on console. How to print current time in R Programming... and time. Following is the example usage of above function to get current date
How to get month name from date(like-25/06/2012) using java?
How to get month name from date(like-25/06/2012) using java?  How to get month name from date(like-25/06/2012) using java
how to get harddisk info using S.M.A.R.T using java
how to get harddisk info using S.M.A.R.T using java   how to get harddisk info using S.M.A.R.T using java
How to display the current time
How to display the current time  I was develop online web portal. In this web portal i am going to display time. I am using <%= new java.util.Date() %> to display the time. But it display the time after that cannot changed

Ads