天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
Java.util.Date类型格式化输出和字符串转Date类型
 1 import java.text.Format;
 2 import java.text.ParseException;
 3 import java.text.SimpleDateFormat;
 4 import java.util.Date;
 5 
 6 public class DateFormatToString {
 7     protected static Format format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 8 
 9     public static void main(String[] args) {
10 
11         Date date = new Date();
12         System.out.println(format.format(date));
13 
14         try {
15             Date date1 = (Date) format.parseObject("2005-11-15 20:55:48");
16             System.out.println(date1);
17         } catch (ParseException e) {
18             // TODO Auto-generated catch block
19 
20         }
21 
22         format = new SimpleDateFormat("yyyy-MM-dd");
23         System.out.println(format.format(date));
24         format = new SimpleDateFormat("hh:mm:ss");
25         System.out.println(format.format(new Date()));
26 
27     }
28 }

输出
12005-11-15 09:02:30
2Tue Nov 15 20:55:48 CST 2005
32005-11-15
409:02:30

posted on 2005-11-16 16:59 bluesky 阅读(7589) 评论(0)  编辑  收藏 所属分类: 基础知识


只有注册用户登录后才能发表评论。


网站导航: