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 );}}