发布网友 发布时间:2022-05-16 20:29
共1个回答
热心网友 时间:2024-03-01 18:05
* ★1.只有日期没有时间* public class DateTest{* public static void main(String args[]){Calendar cal=Calendar.getInstance();String date,day,month,year;year =String.valueOf(cal.get(Calendar.YEAR));month =String.valueOf(cal.get(Calendar.MONTH)+1);day =String.valueOf(cal.get(Calendar.DATE));date = year+-+month+-+day;System.out.println(date);* }* }*//******************************************************************************** ★2.有具体日期和时间分以及秒,但是Date().toLocaleString()已经过 时* public class DateTest {* public static void main(String[] args) {* System.out.println(new java.util.Date().toLocaleString());* }* }******************************************************************************/public class DateTest{public static void main(String args[]){* 格式化日期public class DateTest {public static void main(String[] args) {Calendar cl=Calendar.getInstance();格式化日期 SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);String str = sdf.format(cl.getTime());System.out.println(str);}}************************************************************************************/public class DateTest{public static void main(String args[]){Date date=new Date();