Java date encapsulation and MyMy97DatePicker date plugin usage Summary

Source: Internet
Author: User

/*** @ Author xiaoqun. yi date tool class */public class DateTimeHelper {/*** get current year * @ return yyyy */public static String getCurrentYear () {Calendar Ar c = Calendar ar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); // obtain the UTC + 8 time String year = String. valueOf (c. get (Calendar. YEAR); // get year return YEAR;}/*** get current month * Format: mm */public static String getCurrentMonth () {Calendar Ar c = Calendar ar. getInstance (TimeZone. getTimeZone ("GM T + 08:00 "); // obtain the time String month = String. valueOf (c. get (Calendar. MONTH) + 1). length () = 2? String. valueOf (c. get (Calendar. MONTH) + 1): "0" + String. valueOf (c. get (Calendar. MONTH) + 1); return month;}/*** get the current day * @ return dd before less than 10 fill 0 */public static String getCurrentDay () {Calendar c = Calendar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); // obtain the UTC + 8 time String day = String. valueOf (c. get (Calendar. DAY_OF_MONTH )). length () = 2? String. valueOf (c. get (Calendar. DAY_OF_MONTH) + 1): "0" + String. valueOf (c. get (Calendar. DAY_OF_MONTH); return day;}/*** get current hour * @ return mm less than 10 Add 0 */public static String getCurrentHour () {Calendar c = Calendar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); // obtain the UTC + 8 time String hour = String. valueOf (c. get (Calendar. HOUR_OF_DAY )). length () = 2? String. valueOf (c. get (Calendar. HOUR_OF_DAY): "0" + String. valueOf (c. get (Calendar. HOUR_OF_DAY); return hour;}/*** get the current minute * @ return mm less than 10 and add 0 */public static String getCurrentMinute () {Calendar Ar c = Calendar ar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); // obtain the UTC + 8 time String min = String. valueOf (c. get (Calendar. MINUTE )). length () = 2? String. valueOf (c. get (Calendar. MINUTE): "0" + String. valueOf (c. get (Calendar. MINUTE); return min;}/*** get the current date * @ return yyyy-MM-dd */public static String getCurrentDate () {Calendar ar calendar = Calendar ar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd"); return sdf. format (new Timestamp (calendar. getTime (). getTime ();}/***** @ param month previous months * @ param day a few days ago * @ return yyyyMMdd */public static String getBeforeDate (int month, int day) {Calendar calendar = Calendar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); calendar. add (Calendar. MONTH, month); // obtain the previous calendar. add (Calendar. DATE, day); // obtain the previous SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd"); return sdf. format (new Timestamp (calendar. getTime (). getTime ();}/*** format display date * @ param str yyyyMMdd * @ return yyyy MM dd */public static String formtDate (String str) {return str. substring (0, 4) + "year" + str. substring (4, 6) + "month" + str. substring (6, 8) + "day";}/*** get the current System time, * @ return Timestamp */public static Timestamp getNowTimestamp () {return new Timestamp (System. currentTimeMillis ();}/*** current System time * @ return Date */public static Date getNowDate () {return new Date (System. currentTimeMillis ();}/*** get the current time String * @ param pattern formatted String * @ return */public static String getNowDateStr (String pattern) {SimpleDateFormat sdf = new SimpleDateFormat (pattern); return sdf. format (new Date (System. currentTimeMillis ()));} /*** convert the time conversion String to the time * @ param dateStr String * @ param pattern format * @ return Timestamp */public static Timestamp convertToTimestamp (String dateStr, String pattern) {try {SimpleDateFormat sdf = new SimpleDateFormat (pattern); Date date = sdf. parse (dateStr); return new Timestamp (date. getTime ();} catch (Exception e) {e. printStackTrace ();} return null;}/***** @ param timeMillis time conversion String * @ param pattern * @ return */public static String converToStr (long timeMillis, String pattern) {Timestamp t = new Timestamp (timeMillis); return convert (t, pattern );} /*** convert time String to time * @ param dateStr * @ param pattern * @ return Date */public static Date convertToDate (String dateStr, String pattern) {try {SimpleDateFormat sdf = new SimpleDateFormat (pattern); return sdf. parse (dateStr);} catch (Exception e) {e. printStackTrace ();} return null;}/*** time conversion time String * @ param timestamp * @ param pattern * @ return String */public static String convert (Timestamp timestamp, string pattern) {if (timestamp = null) {return null;} SimpleDateFormat sdf = new SimpleDateFormat (pattern); return sdf. format (new Date (timestamp. getTime ()));} /*** convert time to String * @ param date * @ param pattern * @ return String */public static String conver (Date date, String pattern) {if (date = null) {return null;} SimpleDateFormat sdf = new SimpleDateFormat (pattern); return sdf. format (date);}/*** increase the number of days * @ param currentmi * @ param day * @ return Date */public static Date addDateTime (long currentmi, int day) {Calendar cl = Calendar. getInstance (); cl. setTimeInMillis (currentmi); cl. add (Calendar. DATE, day); return new Date (cl. getTimeInMillis ());} /*** add a certain number of days to the time * @ param currentmi * @ param day * @ param pattern * @ returnn String */public static String addDateTimeToStr (long currentmi, int day, String pattern) {Calendar cl = Calendar. getInstance (); cl. setTimeInMillis (currentmi); cl. add (Calendar. DATE, day); long result = cl. getTimeInMillis (); return conver (new Date (result), pattern);}/*** get the first day of the current month * @ return Timestamp */public static Timestamp getFirstDayOfMonth () {Calendar cal = Calendar. getInstance (); cal. set (GregorianCalendar. DAY_OF_MONTH, 1); return new Timestamp (cal. getTime (). getTime ();}/*** get the first day of the current month * @ return yyyyMMdd */public static String getCurrentMonthFirstDay1 () {SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd "); return sdf. format (getFirstDayOfMonth ();}/*** get the first day of the current month * @ return yyyy MM dd/public static String getCurrentMonthFirstDay2 () {SimpleDateFormat sdf = new SimpleDateFormat ("MM dd, yyyy"); return sdf. format (getFirstDayOfMonth ();}/*** get the last day of the month * @ return Timestamp */public static Timestamp getLastDayOfMonth () {Calendar ar cal = Calendar ar. getInstance (); cal. set (Calendar. DATE, 1); cal. roll (Calendar. DATE,-1); return new Timestamp (cal. getTime (). getTime ();}/*** get the last day of the current month * @ return yyyyMMdd */public static String getCurrentMontLastDay1 () {Calendar ar cal = Calendar ar. getInstance (); cal. set (Calendar. DATE, 1); cal. roll (Calendar. DATE,-1); SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd"); return sdf. format (cal. getTime ();}/** get the last day of the current month * return yyyy-mm-dd * @ return yyyy-MM-dd */public static String getcurrentmonlastday2 () {SimpleDateFormat sdf = new SimpleDateFormat ("MM dd, yyyy"); return sdf. format (getLastDayOfMonth ();}/*** get the previous day of today * @ return yyyyMMdd */public static String getOneDayfore () {Calendar ar calendar = Calendar ar. getInstance (TimeZone. getTimeZone ("GMT + 08:00"); calendar. add (Calendar. DATE,-1); // obtain the previous SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd"); return sdf. format (new Timestamp (calendar. getTime (). getTime ()));}}

Defines public-introduced files: include. inc

<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
 <% @ Page language = "java" import = "com. chinacreator. code. utils. dateTimeHelper "%> <% @ taglib prefix =" c "uri =" http://java.sun.com/jsp/jstl/core "%> <% // context path String contextPath = request. getContextPath (); // topic path String themePath = "/template/themes/default"; String filePath = "jsp/fileupload/"; String year = DateTimeHelper. getCurrentYear (); String month = DateTimeHelper. getCurrentMonth (); String day = DateTimeHelper. getCurrentDay (); String hour = DateTimeHelper. getCurrentHour (); String minute = DateTimeHelper. getCurrentMinute (); String currentDay = DateTimeHelper. getCurrentDate (); // obtain the current date format of the system. The format is yyyy-mm-ddString beforeOneDay = DateTimeHelper. getBeforeDate (0,-1); // obtain the format of yyyy-mm-ddString nextOneDay = DateTimeHelper from the previous day. getBeforeDate (); // get the date yyyy-mm-ddpageContext.setAttribute ("themePath", themePath); pageContext. setAttribute ("contextPath", contextPath); pageContext. setAttribute ("filePath", filePath); pageContext. setAttribute ("year", year); pageContext. setAttribute ("month", month); pageContext. setAttribute ("day", day); pageContext. setAttribute ("hour", hour); pageContext. setAttribute ("minute", minute); pageContext. setAttribute ("hour", hour); pageContext. setAttribute ("minute", minute); pageContext. setAttribute ("currentDay", currentDay); pageContext. setAttribute ("beforeOneDay", beforeOneDay); pageContext. setAttribute ("nextOneDay", nextOneDay); %>
 <Script type = "text/javascript" src = "$ {contextPath }$ {themePath}/js/jquery-1.4.2.js"> </script>
 <Script type = "text/javascript" src = "$ {contextPath }$ {themePath}/js/paging. js"> </script>
 <Script type = "text/javascript" src = "$ {contextPath }$ {themePath}/js/common. js"> </script>
 <Script type = "text/javascript" src = "$ {contextPath }$ {themePath}/js/checkidcard. js"> </script>
 
 
 <Script type = "text/javascript" src = "$ {contextPath}/plugs/My97DatePicker/WdatePicker. js"> </script>
 <Script type = "text/javascript" src = "$ {contextPath}/plugs/FusionCharts/JSClass/FusionCharts. js"> </script>
 <Script type = "text/javascript" src = "$ {contextPath}/plugs/ztree/js/jquery. ztree. all-3.5.min.js "> </script> <script> var themePath =" <% = themePath %> "; var contextPath =" <% = contextPath %> "; var filePath = "<% = filePath %>"; var year = "<% = year %>"; var month = "<% = month %> "; var day = "<% = day %>"; var hour = "<% = hour %>"; var minute = "<% = minute %> "; var currentDay = "<% = currentDay %>"; var beforeOneDay = "<% = beforeOneDay %>"; var nextOneDay = "<% = nextOneDay %>"; </script>

Jsp page introduction:
<% @ Include file = "/template/include. inc" %>
After this file is included, the system obtains the set property value, introduced style, js file, and global js variables defined.

Public query condition Bean:

In the java class
Bean inherits BaseQuery

/***** @ Author xiaoqun. yi */public class BaseQuery implements Serializable {/*****/private static final long serialVersionUID =-2128648445206020540L; // use private String startDate as the query condition; private String endDate; private String keywords; private String dept_name; private String emp_name; public String getStartDate () {return startDate;} public void setStartDate (String startDate) {this. startDate = startDate;} public String getEndDate () {return endDate;} public void setEndDate (String endDate) {this. endDate = endDate;} public String getKeywords () {return keywords;} public void setKeywords (String keywords) {this. keywords = keywords;} public String getDept_name () {return dept_name;} public void setDept_name (String dept_name) {this. dept_name = dept_name;} public String getEmp_name () {return emp_name;} public void setEmp_name (String emp_name) {this. emp_name = emp_name ;}}

The time comparison uses the string yymmdd, which is convenient and does not need to be converted.
Penalty time: the maximum time cannot be greater than the current time. maxDate: 'currentday' is used here. This is the currentDay included in the file introduced earlier. currentDay is the server time.
The second date is later than the first date. The displayed date value is: yyyy-mm-dd. The actual date value is yyyymmdd (the date is the server time)

 --



SQL: xml is used. In fact, the same does not apply to xml. If the condition is not null, a condition is added.
# If ($ startDate &&! $ StartDate. equals (""))
And p. peccancy_time >=# [startDate]
# End
# If ($ endDate &&! $ EndDate. equals (""))
And p. peccancy_time <= # [endDate]
# End

The selected date cannot be greater than the current date (the date is the server time) maxDate: 'currentday'

 


The selected minimum date is later than the current date and later than the previous date. The date format is yyyy-mm-dd. The value is yyyymmdd (the date is the server time)

 

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + yejWw8SsyM + 3/queues/s7xxvfKsbzkKTwvcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java;">

Set the last day of the default server time (the date is the server time)

 

SQL displays the date (oracle) date stored in the database using the string yyyymmdd for convenient comparison
Substr (r. timelimit, 1, 4) "| '-' | substr (r. timelimit, 5, 2) | '-' | substr (r. timelimit, 7,2) as timelimit,


Time: display as hh: the actual value is hhmi for the convenience of the two time periods (the date is the server time)

 

Var starttime = $ ("# date01"). val ();
Starttime = starttime. substring (0, 2) + starttime. substring (3, 5 );
Var endtime = $ ("# date02"). val ();
Endtime = endtime. substring (0, 2) + endtime. substring (3, 5 );
$ ("# Starttime_add"). val (starttime );
$ ("# Endtime_add"). val (endtime );
SQL query display (oracle)
Substr (t. starttime, 1, 2) | ':' | substr (t. starttime, 3, 2) as starttime,
Substr (t. endtime, 1, 2) | ':' | substr (t. endtime, 3, 2) as endtime,



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.