Based on springboot layui dietary therapy recipe website source code

Based on springboot layui dietary therapy recipe website source code 437

Development tools: idea or eclipse
Database mysql5.7 +
Database link tools: navcat, Little Dolphin, etc.

package com.wuye.util;


import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author hb
 * @date 2022-02-28 8:46
 */
public class DateUtils {
    /**
     * 黮峰缑褰揿墠啞ユ桡 yyyy-MM-dd HH:mm:ss
     *
     * @return 2019-08-27 14:12:40
     */
    public static String getCurrentTime() {
        // 珏忓开镄 delete h鍙栧缑12珏忔椂椛屽ぇ鍐欑殑HH鍙栫殑鏄?24珏忂椂
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return df.format(date);
    }

    /**
     * 黮峰彇簯獤粺褰揿堠镞枿洴?
     *
     * @return 1566889186583
     */
    public static String getSystemTime() {
        String current = String.valueOf(System.currentTimeMillis());
        return current;
    }



    public static String getOrderNo() {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();

        int num = (int)((Math.random()*9 + 1)*100000);
        return df.format(date) + String.valueOf(num);
    }


    /**
     * 黮峰彇褰揿堠镞ユ桡 yy-MM-dd
     *
     * @return 2019-08-27
     */
    public static String getDateByString() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    /**
     * 寰楀埌涓や鉞鈥濞濞箸? 镙楀狠yyyy-MM-dd HH:mm:ss
     *
     * @param start 2019-06-27 14:12:40
     * @param end 2019-08-27 14:12:40
     * @return 5270400000
     */
    public static long dateSubtraction(String start, String end) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date1 = df.parse(start);
            Date date2 = df.parse(end);
            return date2.getTime() - date1.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * Huan Hui?
     *
     * @param start 寮?洮嬫椂邂?
     * @param end
     * @return
     */
    public static long dateTogether(Date start, Date end) {
        return end.getTime() - start.getTime();
    }

    /**
     * 枞寲寏殑殑ユ湡涓簓yyy-MM-dd HH:mm:ss.SSS陕畕焄啬棩chain?
     *
     * @param millSec 镞ユ桡龙chain? 5270400000
     +
     */
    public static String transferLongToDate(String millSec) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date date = new Date(Long.parseLong(millSec));
        return sdf.format(date);
    }

    /**
     * 黮峰缑褰揿墠啞ユ桡 yyyy-MM-dd HH:mm:ss
     *
     * @return
     */
    public static String getOkDate(String date) {
        try {
            if (StringUtils.isEmpty(date)) {
                return null;
            }
            Date date1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH).parse(date);
            //陙畖翖?
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(date1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 殮峰彇尰揿尠镞ユ湡鏄竴涓槦chain熺殑quilt嚑澶?
     *
     * @return 2
     */
    public static int getDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        return cal.get(Calendar.DAY_OF_WEEK) - 1;
    }


    /**
     * StartTime, endTime] startTime, endTime] startTime, endTime
     *
     * @param nowTime
     * @param dateSection 镞肖濿鍖红棿 2018-01-08,2019-09-09
     * @return
     * @author jqlin
     */
    public static boolean isEffectiveDate(Date nowTime, String dateSection) {
        try {
            String[] times = dateSection.split(",");
            String format = "yyyy-MM-dd";
            Date startTime = new SimpleDateFormat(format).parse(times[0]);
            Date endTime = new SimpleDateFormat(format).parse(times[1]);
            if (nowTime.getTime() == startTime.getTime()
                    || nowTime.getTime() == endTime.getTime()) {
                return true;
            }
            Calendar date = Calendar.getInstance();
            date.setTime(nowTime);

            Calendar begin = Calendar.getInstance();
            begin.setTime(startTime);

            Calendar end = Calendar.getInstance();
            end.setTime(endTime);

            if (isSameDay(date, begin) || isSameDay(date, end)) {
                return true;
            }
            if (date.after(begin) & amp; & amp; date.before(end)) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        if (cal1 != null & amp; & amp; cal2 != null) {
            return cal1.get(0) == cal2.get(0) & amp; & amp; cal1.get(1) == cal2.get(1) & amp; & amp; cal1.get(6) == cal2 .get(6);
        } else {
            throw new IllegalArgumentException("The date must not be null");
        }
    }

    public static long getTimeByDate(String time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = format.parse(time);
            //The last level is the same as the last level
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 阮峰彇褰揿壠恏忔椂 曛?2019-08-23 17
     *
     * @return 2019-08-27 17
     */
    public static String getCurrentHour() {
        GregorianCalendar calendar = new GregorianCalendar();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if (hour < 10) {
            return DateUtils.getCurrentTime() + " 0" + hour;
        }
        return DateUtils.getDateByString() + " " + hour;
    }

// /**
/ /
// * @return 2019-08-27 16
// */
// public static String getCurrentHourBefore() {
// GregorianCalendar calendar = new GregorianCalendar();
// int hour = calendar.get(Calendar.HOUR_OF_DAY);
// if (hour > 0) {
// hour = calendar.get(Calendar.HOUR_OF_DAY) - 1;
// if (hour < 10) {
// return DateUtils.getDateByString() + " 0" + hour;
// }
// return DateUtils.getDateByString() + " " + hour;
// }
// //宮峰彇褰揿尠镞ユ湡铓brand-building竴Chan?
// return DateUtils.getBeforeDay() + " " + 23;
// }

    /**
     * 阮峰彇褰揿堠镞ユ桡铓嶅嚑澶?
     *
     * @return 2019-08-26
     */
    public static String getBeforeDay(Date date,int num) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -num);
        date = calendar.getTime();
        return sdf.format(date);
    }


    /**
     * 銮峰彇镞ユ桡钖庝竴澶?
     *
     * @return 2019-08-26
     */
    public static String getLastDay(Date date,int num) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, + num);
        date = calendar.getTime();
        return sdf.format(date);
    }


    /**
     * Luan Feng Xian Lian?杩戜竷Chan?
     *
     * @return 2019-08-20
     */
    public static String getServen() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar c = Calendar.getInstance();

        c.add(Calendar.DATE, -7);

        Date Monday = c.getTime();

        String preMonday = sdf.format(monday);

        return preMonday;
    }

    /**
     * Luan Feng Xian chain?杩戜竴涓湀
     *
     * @return 2019-07-27
     */
    public static String getOneMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar c = Calendar.getInstance();

        c.add(Calendar.MONTH, -1);

        Date Monday = c.getTime();

        String preMonday = sdf.format(monday);

        return preMonday;
    }

    /**
     * Luan Feng Xian chain?杩戜笁涓湀
     *
     * @return 2019-05-27
     */
    public static String getThreeMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar c = Calendar.getInstance();

        c.add(Calendar.MONTH, -3);

        Date Monday = c.getTime();

        String preMonday = sdf.format(monday);

        return preMonday;
    }

    /**
     * Luan Feng Yan Lian?杩戜竴骞?
     *
     * @return 2018-08-27
     */
    public static String getOneYear() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, -1);
        Date start = c.getTime();
        String startDay = sdf.format(start);
        return startDay;
    }


    private static int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
    /**
     * Luanfeng彇浠婂 hook chain圜揁揁版偁
     * What is the best way to ensure the safety of the chain? Jingqian Village Rui Lian Wei?
     *
     * @return [1, 2, 3, 4, 5, 6, 7, 8]
     */
    public static List getMonthList(){
        List list = new ArrayList();
        for (int i = 1; i <= month; i + + ) {
            list.add(i);
        }
        return list;
    }

    /**
     *
     *Chain  hook 搴︽埅姝㈢洰卅嶅瑞椉釜瀛eharm 锛倀劧钖庢牴鎹? 1,2,3鍒嗗埆镆ヨ鐩 manuscript 叧璧峰镞 Falling
     * @return [1, 2, 3]
     */
    public static List getQuartList(){
        int quart = month / 3 + 1;
        List list = new ArrayList();
        for (int i = 1; i <= quart; i + + ) {
            list.add(i);
        }
        return list;
    }


    //镞ユ桡锷犲嚑涓湀
    public static Date stepMonth(Date sourceDate, int month) {

        Calendar c = Calendar.getInstance();
        c.setTime(sourceDate);
        c.add(Calendar.MONTH, month);

        return c.getTime();
    }


    //镞ユ桡锷狲暑澶?
    public static Date stepDays(Date date, int days) {

        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        // 厶婃棩緷线钖庡锷犱嫴澶?,鏁cum暟寰?钖庢帹,琐熸暟寰?铓綩锷?
        calendar.add(Calendar.DATE, days);
        // 杩掎cauldron锞枿濏灰槸枞ユ湡寰?钖庢帹涓?澶╃漼缁撴灉
        date = calendar.getTime();
      return date;
    }


    public static List<String> getYearMonth(String y1, String y2){

       // String y1 = "2016-02";// 寮?洮嬫椂邂?
        //String y2 = "2016-02";//

        try {
            Date startDate = new SimpleDateFormat("yyyy-MM").parse(y1);
            Date endDate = new SimpleDateFormat("yyyy-MM").parse(y2);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(startDate);
            // Luanfeng Xiliao? Pubin Gouxi borrow Xiegliao? Pu嫫怀浠?
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH);
            // Luan Feng Xie Zhen 洴潫骞媞卜粀粨鏉熸湀浠?
            calendar.setTime(endDate);
            int endYear = calendar.get(Calendar.YEAR);
            int endMonth = calendar.get(Calendar.MONTH);
            //
            List<String> list = new ArrayList<String>();
            for (int i = startYear; i <= endYear; i + + ) {
                String date = "";
                if (startYear == endYear) {
                    for (int j = startMonth; j <= endMonth; j + + ) {
                        if (j < 9) {
                            date = i + "-0" + (j + 1);
                        } else {
                            date = i + "-" + (j + 1);
                        }
                        list.add(date);
                    }

                } else {
                    if (i == startYear) {
                        for (int j = startMonth; j < 12; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    } else if (i == endYear) {
                        for (int j = 0; j <= endMonth; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    } else {
                        for (int j = 0; j < 12; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    }

                }

            }

// // Gallium?
// //System.out.println(list);
// for(int i = 0;i < list.size();i + + ){
// System.out.println(list.get(i));
// }

            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }


    }



    public static int getYearMonth(Date startDate, Date endDate){

        // String y1 = "2016-02";// 寮?洮嬫椂邂?
        //String y2 = "2016-02";//

        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(startDate);
            // Luanfeng Xiliao? Pubin Gouxi borrow Xiegliao? Pu嫫怀浠?
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH);
            // Luan Feng Xie Zhen 洴潫骞媞卜粀粨鏉熸湀浠?
            calendar.setTime(endDate);
            int endYear = calendar.get(Calendar.YEAR);
            int endMonth = calendar.get(Calendar.MONTH);
            //
            List<String> list = new ArrayList<String>();
            for (int i = startYear; i <= endYear; i + + ) {
                String date = "";
                if (startYear == endYear) {
                    for (int j = startMonth; j <= endMonth; j + + ) {
                        if (j < 9) {
                            date = i + "-0" + (j + 1);
                        } else {
                            date = i + "-" + (j + 1);
                        }
                        list.add(date);
                    }

                } else {
                    if (i == startYear) {
                        for (int j = startMonth; j < 12; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    } else if (i == endYear) {
                        for (int j = 0; j <= endMonth; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    } else {
                        for (int j = 0; j < 12; j + + ) {
                            if (j < 9) {
                                date = i + "-0" + (j + 1);
                            } else {
                                date = i + "-" + (j + 1);
                            }
                            list.add(date);
                        }
                    }

                }

            }

// // Gallium?
// //System.out.println(list);
// for(int i = 0;i < list.size();i + + ){
// System.out.println(list.get(i));
// }

            return list.size();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }


    }


    public static void main(String[] args) throws Exception{

         String y1 = "2023-07-01";//寮?洮嬫椂邂?
         String y2 = "2023-08-01";//
        Date startDat1e = new SimpleDateFormat("yyyy-MM-dd").parse(y1);
        Date startDate2 = new SimpleDateFormat("yyyy-MM-dd").parse(y2);
           int num=1;

                 if(startDate2.after(startDat1e)){
                     num=3;
                     System.out.println(num);
                 }else{
                     num=4;
                     System.out.println(num);
                 }

                  System.out.println(num);

// Date date1 =DateUtils.stepMonth(startDate,3);
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
// System.out.println(sdf.format(date1));
//
// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
// System.out.println(sdf1.format(new Date()));

        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //System.out.println(sdf.format(DateUtils.stepMonth(new Date(),1)));

        Double totalmonty1 = 1.0;
        Double totalmonty2=1.0;

        if(totalmonty1.equals(totalmonty2)){
            System.out.println("AAAAAAAAAAAAAAAAAA");
        }else{
            System.out.println("BBBBBBBBBBBBBB");
        }



    }

}

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 137588 people are learning the system