Java code
- Import java. Text. simpledateformat;
- Simpledateformat formatter = new simpledateformat ("mm DD, yyyy hh: mm: SS ");
- Date curdate = new date (system. currenttimemillis (); // obtain the current time
- String STR = formatter. Format (curdate );
Import Java. text. simpledateformat; simpledateformat formatter = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); Date curdate = new date (system. currenttimemillis (); // obtain the current time string STR = formatter. format (curdate );
You can obtain the current date and month, or write separately:
Java code
- Simpledateformat sdateformat = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
- String date = sdateformat. Format (New java. util. Date ());
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String date = sDateFormat.format(new java.util.Date());
If you want to obtain the current year and month, you can write it like this (only get the same time or second ):
Java code
- Simpledateformat SDF = new simpledateformat ("yyyy-mm ");
- String date = SDF. Format (New java. util. Date ());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); String date=sdf.format(new java.util.Date());
Of course, you can also specify the time zone (to be ):
DF = dateformat. getdatetimeinstance (dateformat. Full, dateformat. Full, locale. China );
System. Out. println (DF. Format (new date ()));
========================================================== ======================================
Add QQ: 284651035 (this blogger) for help)
Weibo: http://weibo.com/cnbailu (Bai Lu)
Http://weibo.com/u/2717396075 (featured jokes)
Mr Chen Weibo: http://weibo.com/redarmychen Java direction
Miss Li Weibo: http://weibo.com/csdnliwei PHP direction
Mobile (mobile) Software Development Exchange Group: 57636364(Please note that the application is on the csdn blog. Remember to change your business card after entering the group.) Thank you!