怎么获取时间

ww_stone 2004-10-19 11:28:47
怎么获取时间,显示为“1950-10-02”格式,并把它赋值给字符串
...全文
155 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dudee 2004-10-19
  • 打赏
  • 举报
回复
Date time=new Date();
SimpleDateFormat abc = new SimpleDateFormat("yyyy-MM-dd");
String stime=abc.format(time);

System.out.println(stime);
打印出现在时间的xxxx-xx-xx格式.
supersunyi 2004-10-19
  • 打赏
  • 举报
回复
strformat = "yyyy-MM-dd"
SimpleDateFormat form = new SimpleDateFormat(strformat);
GregorianCalendar calendar = new GregorianCalendar();
return form.format(calendar.getTime());
supersunyi 2004-10-19
  • 打赏
  • 举报
回复
strformat
SimpleDateFormat form = new SimpleDateFormat(strformat);
GregorianCalendar calendar = new GregorianCalendar();
return form.format(calendar.getTime());
alpha15 2004-10-19
  • 打赏
  • 举报
回复
import java.util.*;
import java.text.*;
public class Test
{
public static void main(String args[])
{
Date time=new Date();
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
String stime=simple .format(time);
System.out.println(stime);
}
}
cx1999 2004-10-19
  • 打赏
  • 举报
回复
要加上
import java.util.*;
然后用 new date()
alpha15 2004-10-19
  • 打赏
  • 举报
回复
上面所说
apple21 2004-10-19
  • 打赏
  • 举报
回复
Date time=new Date();
SimpleDateFormat abc = new SimpleDateFormat("yyyy-MM-dd");
String stime=abc.format(time);
wtobias 2004-10-19
  • 打赏
  • 举报
回复
up
tttleaf 2004-10-19
  • 打赏
  • 举报
回复
Calendar cal=Calendar.getInstance();
String cur_time = cal.getTime().toString();
也可以
abcdhy 2004-10-19
  • 打赏
  • 举报
回复
有一个更简单的方法:

java.sql.Date date = new java.sql.Date();
System.out.println(date);

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧