How to get the current date and time in Timestamp with Java

1 Answer

0 votes
import java.sql.Timestamp;
import java.time.format.DateTimeParseException;
 
public class MyClass
{
    public static void main(String[] args)
    {
        Timestamp timestamp = null;
  
        try {
            timestamp = new Timestamp(System.currentTimeMillis());
        }
        catch (DateTimeParseException ex) {
            System.out.println(ex.getMessage());
        }
  
        System.out.println(timestamp);
    }
}
 
 
   
   
/*
run:
    
2023-03-22 19:00:44.832
    
*/

 



answered Mar 22, 2023 by avibootz

Related questions

1 answer 172 views
1 answer 185 views
1 answer 190 views
3 answers 259 views
6 answers 434 views
...