Some date operations that are noticed during development are generally called the dateutil class.

Source: Internet
Author: User
Package COM. put. util; import Java. text. parseexception; import Java. text. simpledateformat; import Java. util. calendar; import Java. util. date;/*** @ classname: dateutil * @ Description: time help class * @ author yegz * @ date 10:41:26 */public class dateutil {/*** @ title: getcurrtime * @ Description: yyyy-mm-dd't'hh: mm: SS * @ throws parseexception * @ return date * @ author yegz * @ date 2014-9-12 10:42:25 am */public static date getcurrtime () throws parseexception {simpledateformat df = new simpledateformat ("yyyy-mm-dd't'hh: mm: SS"); // set the date format string datetime = DF. format (new date (); Return DF. parse (datetime);}/*** @ title: getcurrtimestring * @ Description: yyyy-mm-dd't'hh: mm: SS * @ throws parseexception * @ return string * @ author yegz * @ date 2014-9-12 10:41:43 am */public static string getcurrtimestring () throws parseexception {simpledateformat df = new simpledateformat ("yyyy-mm-dd't'hh: mm: SS"); // set the date format return DF. format (new date ();}/*** @ title: getcurrtimetonott * @ Description: yyyy-mm-dd hh: mm: SS * @ throws parseexception * @ return date * @ author yegz * @ date 2014-9-12 10:49:57 am */public static date getcurrtimetonott () throws parseexception {simpledateformat df = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); // set the date format string datetime = DF. format (new date (); Return DF. parse (datetime);}/*** @ title: getcurrtimestringtonott * @ Description: yyyy-mm-dd hh: mm: SS * @ throws parseexception * @ return string * @ author yegz * @ date 2014-9-12 10:50:09 am */public static string getcurrtimestringtonott () throws parseexception {simpledateformat df = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); // set the date format return DF. format (new date ();}/*** @ title: getcurrtimejusthms * @ Description: hh: mm: SS * @ throws parseexception * @ return date * @ author yegz * @ date 2014-9-12 am 10:54:30 */public static date getcurrtimejusthms () throws parseexception {simpledateformat df = new simpledateformat ("HH: MM: SS "); // set the date format string datetime = DF. format (new date (); Return DF. parse (datetime);}/*** @ title: getcurrtimestringjusthms * @ Description: hh: mm: SS * @ throws parseexception * @ return string * @ author yegz * @ date 2014-9-12 am 10:54:51 */public static string getcurrtimestringjusthms () throws parseexception {simpledateformat df = new simpledateformat ("HH: MM: SS "); // set the date format return DF. format (new date ();}/*** @ title: getcurrtimetomyformat * @ Description: custom format, obtain the current time * @ Param Format * @ throws parseexception * @ return date * @ author yegz * @ date 10:59:57 */public static date getcurrtimetomyformat (string format) throws parseexception {simpledateformat df = new simpledateformat (format); // set the date format string datetime = DF. format (new date (); Return DF. parse (datetime);}/*** @ title: getcurrtimestringjusthms * @ Description: custom format, obtain the current time * @ Param Format * @ throws parseexception * @ return string * @ author yegz * @ date 11:00:32 */public static string getcurrtimestringjusthms (string format) throws parseexception {simpledateformat df = new simpledateformat (format); // set the date format return DF. format (new date ();}/*** @ title: getweekshowint * @ Description: displays the number of days in a week, number Display * @ Param date * @ return int * @ author yegz * @ date 11:12:53 */public static int getweekshowint (date) {calendar Cal = calendar. getinstance (); Cal. settime (date); Return Cal. get (calendar. day_of_week)-1;}/*** @ title: getweekshowstring * @ description, text display * @ Param date * @ return string * @ author yegz * @ date 11:13:55 */public static string getweekshowstring (date) {calendar ar Cal = calendar. getinstance (); string week = ""; Cal. settime (date); int today = Cal. get (calendar. day_of_week)-1; Switch (today) {Case 1: Week = "Monday"; break; Case 2: Week = "Tuesday"; break; Case 3: week = "Wednesday"; break; Case 4: Week = "Thursday"; break; Case 5: Week = "Friday"; break; Case 6: Week = "Saturday "; break; Case 0: Week = "Sunday"; break; default: break;} return week;}/*** @ title: gettodayweekshowint * @ Description: get today's Week, number Display * @ return int * @ author yegz * @ date 11:14:32 */public static int gettodayweekshowint () {calendar Cal = calendar. getinstance (); Cal. settime (new date (); Return Cal. get (calendar. day_of_week)-1;}/*** @ title: gettodayweekshowstring * @ Description: get today's Week, text display * @ return string * @ author yegz * @ date 11:15:20 */public static string gettodayweekshowstring () {calendar Cal = calendar. getinstance (); string week = ""; Cal. settime (new date (); int today = Cal. get (calendar. day_of_week)-1; Switch (today) {Case 1: Week = "Monday"; break; Case 2: Week = "Tuesday"; break; Case 3: week = "Wednesday"; break; Case 4: Week = "Thursday"; break; Case 5: Week = "Friday"; break; Case 6: Week = "Saturday "; break; Case 0: Week = "Sunday"; break; default: break;} return week;}/** test */public static void main (string [] ARGs) throws parseexception {// system. out. println (dateutil. getcurrtimestringjusthms (); // system. out. println (dateutil. gettodayweekshowint (new date (); system. out. println (dateutil. gettodayweekshowstring ());}}


This article is from the "9132951" blog, please be sure to keep this source http://9142951.blog.51cto.com/9132951/1551622

Some date operations that are noticed during development are generally called the dateutil class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.