20-obtain the string format of the current system time (string processing)

Source: Internet
Author: User

Stringutil. Java

Package COM. LH. bean; import Java. text. simpledateformat; import Java. util. calendar; import Java. util. date; public class stringutil {// Date string private string timestr1; private string timestr2; // use the Calendar Object method Public String gettimestr1 () {// create the Calendar Object calendar c = calendar. getinstance (); // get the year, month, and day of the current time int year = C. get (C. year); int month = C. get (C. month) + 1; int day = C. get (C. day_of_month); int hour = C. get (C. hour_of_day); int minute = C. get (C. minute); int second = C. get (C. second); timestr1 = year + "-" + month + "-" + day + "-" + hour + ":" + minute + ":" + second; return timestr1;} // obtain the current time of the system using the date object Public String gettimestr2 () {// create a date object that represents the current time date = new date (); // create the format Date and Time object simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); timestr2 = format. format (date); Return timestr2 ;}}

 

Index. jsp

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <HTML> 

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.