import java.text.SimpleDateFormat; import java.util.Date; class Test { public static void main(String[] args) { Date today=new Date(); SimpleDateFormat sfd= new SimpleDateFormat("yyyy-MM-dd"); String date=sfd.format(today); //String date=today.getYear()+"-"+today.getMonth()+"-"+today.getDay(); System.out.println("现在的日期是"+date); } } |