javadatecurrent-time

java get the current computer's date


how can i get computer's date on java, i want just year, month, day. Like

2012-07-01

i tried to get calender like this

Calendar c =Calendar.getInstance();
        c.clear(Calendar.HOUR)

but can't know to deal with it,


Solution

  • First link on google:

    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    
    private String getDateTime() {
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            return dateFormat.format(date);
        }