发布网友 发布时间:2022-04-23 13:43
共2个回答
热心网友 时间:2023-10-16 07:13
import java.util.*;
import java.text.SimpleDateFormat;
public class test
{
public static void main (String args[])
{
Date d = new Date();
long longtime = d.getTime();
System.out.println(longtime);
//你获得的是上面的long型数据吧
String time = d.toLocaleString();
//你可以简单的得到本地化时间,本来就是String类型的就不用转换了
System.out.println(time);
//也可以自己用SimpleDateFormat这个函数把它变成自己想要的格式,注意需要import java.text.SimpleDateFormat;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(longtime));
}
}
热心网友 时间:2023-10-16 07:13
import java.text.SimpleDateFormat;
//import java.util.Date;
import java.util.*;
public class DateTest
{
public static void main(String[] args)
{
Date myDate=new Date(System.currentTimeMillis());
//This time format is your local time format.
System.out.println(myDate.toString());
//Used the simple format to get the String you want .
//The valid string ,you can reference the JDK Doc
SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(sDateFormat.format(myDate));
GregorianCalendar Day=new GregorianCalendar();
int yyyy,mm,dd;
yyyy=Day.get(Calendar.YEAR);
mm=Day.get(Calendar.MONTH)+1;
dd=Day.get(Calendar.DATE);
System.out.println(Integer.toString(yyyy)+"-"+Integer.toString(mm)+"-"+Integer.toString(dd)) ;
System.out.println(new java.util.Date());
//System.out.println((new java.util.Date()).getTime());
}
}