java中Date的格式.pdf





《java中Date的格式.pdf》由会员分享,可在线阅读,更多相关《java中Date的格式.pdf(3页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、使用系统的当前日期和时间创建一个日期对象并返回一个长整数的简单例子。这个时间通常被称为Java import java.util.Date;public class DateExample1 public static void main(String args)/Get the system date/time Date date=new Date();System.out.println(date.getTime();import java.text.SimpleDateFormat;import java.util.Date;public class DateExample2 publi
2、c static void main(String args)SimpleDateFormat bartDateFormat=new SimpleDateFormat(EEEE-MMMM-dd-yyyy);Date date=new Date();System.out.println(bartDateFormat.format(date);import java.text.SimpleDateFormat;import java.util.Date;public class DateExample3 public static void main(String args)/Create a d
3、ate formatter that can parse dates of the form MM-dd-yyyy.SimpleDateFormat bartDateFormat=new SimpleDateFormat(MM-dd-yyyy);/Create a string containing a text date to be parsed.String dateStringToParse=8-8-2005;try /Parse the text version of the date./We have to perform the parse method in a/try-catc
4、h construct in case dateStringToParse/does not contain a date in the format we are expecting.Date date=bartDateFormat.parse(dateStringToParse);/Now send the parsed date as a long value/to the system output.System.out.println(date.getTime();catch(Exception ex)System.out.println(ex.getMessage();05-8-8
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java Date 格式

限制150内