import java.sql.Timestamp; import java.text.SimpleDateFormat; public class Start { // Define the format for the time stamp private static final SimpleDateFormat FORMAT_DATE = new SimpleDateFormat("yyyy-MM-dd"); private static final SimpleDateFormat FORMAT_TIME = new SimpleDateFormat("HH:mm"); public static void main(String[] args) { // Get the current date and time Timestamp timestemp = new Timestamp(System.currentTimeMillis()); // Output the timestamp formated as date and time System.out.println("Current Date: " + FORMAT_DATE.format(timestemp)); System.out.println("Current Time: " + FORMAT_TIME.format(timestemp)); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter