欢迎来到天天文库
浏览记录
ID:8978205
大小:15.58 KB
页数:2页
时间:2018-04-13
《java使用dateformat类转换时间格式》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、java使用DateFormat类,转换时间格式显示源文件复制到剪贴板打印关于1.import java.util.Date; 2.import java.text.DateFormat; 3. 4./** 5. * 格式化时间类 6. * DateFormat.FULL = 0 7. * DateFormat.DEFAULT = 2 8. * DateFormat.LONG = 1 9. * DateFormat.MEDIUM = 2 10. * DateFormat.SHORT = 3 1
2、1. */ 12. 13.public class FormatDate{ 14. public static void main(String []args){ 15. Date d = new Date(); 16. String s; 17. 18. /** Date类的格式: Sat Apr 16 13:17:29 CST 2005 */ 19. System.out.println(d); 20. 21.
3、 System.out.println("******************************************"); 22. 23. /** getDateInstance() */ 24. /** 输出格式: 2005-4-16 */ 25. s = DateFormat.getDateInstance().format(d); 26. System.out.println(s); 27. 28.
4、 /** 输出格式: 2005-4-16 */ 29. s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d); 30. System.out.println(s); 31. 32. /** 输出格式: 2005年4月16日 星期六 */ 33. s = DateFormat.getDateInstance(DateFormat.FULL).format(
5、d); 34. System.out.println(s); 35. 36. /** 输出格式: 2005-4-16 */ 37. s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d); 38. System.out.println(s); 39. 40. /** 输出格式: 05-4-16 */ 41. s = DateFormat.
6、getDateInstance(DateFormat.SHORT).format(d); 1. System.out.println(s); 2. 3. System.out.println("******************************************"); 4. } 5.}
此文档下载收益归作者所有