How to Get the current date and time
This code will print the current Date and Time to the console.
Code Java:
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateAndTime{
public static final String DATE_FORMAT_NOW = "dd-MM-yyyy HH:mm:ss";
public static String dt;
public static String DateTime()
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}
public static void main(String[] args){
DateAndTime dAT = new DateAndTime();
dt = dAT.DateTime();
System.out.println(dt);
}
}
Output example:
Quote:
19-05-2008 13:35:07
Re: How to Get the current date and time
Very good, but the time is a hour late,
however most likely it is because we have day light saving (Summer in New Zealand)
There are a lot of dreamer running the radio station, wanting a white (Snow) Christmas
Re: How to Get the current date and time
Hello Eric.
Thank you very much for bringing that to my attention. +Rep points for you..