JSP time operation

xiaoxiao2021-03-06  88

I often see the issue of someone in the JSP version, which generally includes: take the current time, transform a specified string time into time type, find the number of days between two times, seeking a period of time before, seeking time Summary of these issues after a period of time.

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ Page Import = "Java.Text. *"%> <% @ Page import = "java.util. *"%> <% / / String transformation into time type (string can be any type, as long as the format in SimpleDateFormat can be consistent) Java.Text.Text.SIMPLDATEDATEFORMAT ("M / DD / YYYY HH: mm: ss a ", java.util.locale.us); java.util.date d = sdf.parse (" 5/13/2003 10:31:37 AM "); out.println (d); Out.println ("
"); SimpleDateFormat Formatter = new SimpleDateFormat (" YYYY-MM-DD HH: MM: SS "); string mdatetime1 = formatter.format (d); out.println (mdatetime1); Out.println ("
"); out.println (d.gettime ()); out.println ("
"); // Current time Calendar Cal = Calendar.GetInstance (); // simpledateformat formatter = new SimpleDateFormat (" YYY- MM-DD HH: MM: SS "); SimpleDateFormat Formatter = New SimpleDateFormat (" YYYY-MM-DD HH: MM: SS GEDF W W a EF "); string mdatetime = formatter.format (Cal.getTime ()); Out.println; Out.println ("
"); // 1 year ago java.util.date mydate = new java.util.date (); long mytime = (MyDate.getTime () / 1000) -60 * 60 * 24 * 365; mydate.settime; string mdate = formatter.format (mydate); out.println (mdate); out.println ("
"); // Timark MYDATE = New Java.util.date ( ); Mytime = (mydate.gettime () / 1000) 60 * 60 * 24; mydate.settime (MyTime * 1000); mdate = formatter.format (mydate); out.println (MDATE); out.println ("
"); // The number of days between two times SimpleDateFormat myformatter = new simpledateformat (" YYYY-MM-DD "); java.util.date date = myformatter.parse (" 2003-05-1 ");

转载请注明原文地址:https://www.9cbs.com/read-107546.html

New Post(0)