Date formatting in different languages

Source: Internet
Author: User

About date formatting is a pain for almost all programmers. Although it is not difficult to format a date, it is absolutely difficult to remember all the daily start formatting methods in different languages. But today, the editor has organized the date formatting methods in different languages, so you no longer have to worry about formatting the date. 1. Format date JSTL 1 in JSP page <% @ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %> Format date 1 in JSP page <fmt: formatDate value = "$ {result. showDate} "type =" both "pattern = yyyy-MM-dd/> 2. format the Date using JS. prototype. format = function (fmt) {var o = {"M +": this. getMonth () + 1, // "d +": this. getDate (), // "h +": this. getHours (), // Hour "m +": this. getMinutes (), // "s +": this. getSeconds (), // "q +": Math. floor (this. ge TMonth () + 3)/3), // "S": this. getMilliseconds () //}; if (/(y + )/. test (fmt) fmt = fmt. replace (RegExp. $1, (this. getFullYear () + ""). substr (4-RegExp. $1. length); for (var k in o) if (new RegExp ("(" + k + ")"). test (fmt) fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length); return fmt;} // returns var time1 = new Date (). format ("yyyy-MM-dd"); var time2 = new Date (). format ("yyyy-MM-dd HH: mm: ss"); 3. Use Java to Format the date import java. text. parseException; import java. text. simpleDateFormat; import java. util. calendar; import java. util. date; import org. apache. commons. lang. stringUtils; public class DateUtil {private static SimpleDateFormat df = n Ew SimpleDateFormat ("yyyy-MM-dd "); /*** Meimei has a specified interval yyyy-MM-dd before the interval * @ param dealDate * @ return */public static String getMonthFirstDay (Date dealDate) {Calendar calendar = Calendar. getInstance (); if (dealDate! = Null) {calendar. setTime (dealDate);} calendar. set (Calendar. DATE, 1); return df. format (calendar. getTime ());} /*** Mei's previous example is yyyy-MM-dd. Mei's previous example is @ param dealDate * @ return */public static String getMonthLastDay (Date dealDate) {Calendar calendar = Calendar. getInstance (); if (dealDate! = Null) {calendar. setTime (dealDate);} calendar. set (Calendar. DAY_OF_MONTH, calendar. getActualMaximum (Calendar. DAY_OF_MONTH); return df. format (calendar. getTime ();}/*** Mei's algorithm * @ param lastDealDate not * @ param intervalMonths path * @ return */public static String getNextDealDate (Date lastDealDate, int intervalMonths) {Calendar cal = Calendar. getInstance (); cal. setTime (lastDealDate); cal. add (cal. MONTH, IntervalMonths); return df. format (cal. getTime ();}/*** Stringate * @ param strDate * @ return * @ throws Exception */public static Date toDate (String strDate) throws Exception {if (StringUtils. isEmpty (strDate) {throw new Exception ("! ");} Return df. parse (strDate);}/*** convert Date to String * @ param date * @ return * @ throws Exception */public static String dateToString (Date date) throws Exception {return df. format (date );}}

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.