How to get current timestamps in Java
Here’s a Java example to show how to get current timestamps in Java.
package com.mkyong.common; import java.sql.Timestamp; import java.util.Date; public class GetCurrentTimeStamp { public static void main( String[] args ) { java.util.Date date= new java.util.Date(); System.out.println(new Timestamp(date.getTime())); } }
output
2010-03-08 14:59:30.252

This helped. Thanks!
real nice and all, but your output is not a timestamp. a timestamp is the number of seconds since january 1 1970. what you’re creating is some sort of arbitrarily formatted date string.
get with it, please.
hello sir/madam,
I have one problem please help me anyone
I have hard code date in my java code for 1 min to 8 hours with 6 currency pairs like
java.sql.Timestamp timestamp = Timestamp.valueOf(“2012-02-24 20:00:00″);
then its working fine.
If i have add for live chart like
java.sql.Timestamp timestamp = new Timestamp(System.currentTimeMillis());
or
java.util.Date date= new java.util.Date();
java.sql.Timestamp timestamp = new Timestamp(today.getTime());
then its taking lot of time to plot the jfreechart graph .
so give me some suggestion or any commands need to add in my java code.
Its urgent please.
This is what I have been searching for days. Thanks !
Both overloaded constructors work great.
This is simpler and avoids using Date
Love this implementation.
^^ This is great!
This is an awesome solution…..
Thanks alot
This is what I have been searching for days. Thanks !
Thanks for this!
You’re welcome.
i like u r website and how to ask questions