基于springboot Vue旅游信息推荐系统前后端分离源码

基于springboot Vue旅游信息推荐系统前后端分离源码442

基于springboot Vue旅游信息推荐系统前后端分离源码开发工具:idea 或eclipse
 数据库mysql5.7+
 数据库链接工具:navcat,小海豚等

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() {
        // 灏忓啓鐨刪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;
        }
    }

    /**
     * 寰楀埌涓や釜鏃堕棿宸�
     *
     * @param start 寮�濮嬫椂闂�
     * @param end 缁撴潫鏃堕棿
     * @return
     */
    public static long dateTogether(Date start, Date end) {
        return end.getTime() - start.getTime();
    }

    /**
     * 杞寲long鍊肩殑鏃ユ湡涓簓yyy-MM-dd  HH:mm:ss.SSS鏍煎紡鐨勬棩鏈�
     *
     * @param millSec 鏃ユ湡long鍊�  5270400000
     * @return 鏃ユ湡锛屼互yyyy-MM-dd  HH:mm:ss.SSS鏍煎紡杈撳嚭 1970-03-03  08:00:00.000
     */
    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;
    }


    /**
     * 鑾峰彇褰撳墠鏃ユ湡鏄竴涓槦鏈熺殑绗嚑澶�
     *
     * @return 2
     */
    public static int getDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        return cal.get(Calendar.DAY_OF_WEEK) - 1;
    }


    /**
     * 鍒ゆ柇褰撳墠鏃堕棿鏄惁鍦╗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) && 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 && cal2 != null) {
            return cal1.get(0) == cal2.get(0) && cal1.get(1) == cal2.get(1) && 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);
            //鏃ユ湡杞椂闂存埑锛堟绉掞級
            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;
//        }
//        //鑾峰彇褰撳墠鏃ユ湡鍓嶄竴澶�
//        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);
    }


    /**
     * 鑾峰彇鏈�杩戜竷澶�
     *
     * @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;
    }

    /**
     * 鑾峰彇鏈�杩戜竴涓湀
     *
     * @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;
    }

    /**
     * 鑾峰彇鏈�杩戜笁涓湀
     *
     * @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;
    }

    /**
     * 鑾峰彇鏈�杩戜竴骞�
     *
     * @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;
    /**
     * 鑾峰彇浠婂勾鏈堜唤鏁版嵁
     * 璇存槑 鏈夌殑闇�姹傚墠绔渶瑕佹牴鎹湀浠芥煡璇㈡瘡鏈堟暟鎹紝姝ゆ椂鍚庡彴缁欏墠绔繑鍥炰粖骞村叡鏈夊灏戞湀浠�
     *
     * @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;
    }

    /**
     * 杩斿洖褰撳墠骞村害瀛e害list
     * 鏈勾搴︽埅姝㈢洰鍓嶅叡涓変釜瀛e害锛岀劧鍚庢牴鎹�1,2,3鍒嗗埆鏌ヨ鐩稿叧璧锋鏃堕棿
     * @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);
        // 鎶婃棩鏈熷線鍚庡鍔犱竴澶�,鏁存暟  寰�鍚庢帹,璐熸暟寰�鍓嶇Щ鍔�
        calendar.add(Calendar.DATE, days);
        // 杩欎釜鏃堕棿灏辨槸鏃ユ湡寰�鍚庢帹涓�澶╃殑缁撴灉
        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);
            // 鑾峰彇寮�濮嬪勾浠藉拰寮�濮嬫湀浠�
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH);
            // 鑾峰彇缁撴潫骞翠唤鍜岀粨鏉熸湀浠�
            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);
                        }
                    }

                }

            }

//            // 鎵�鏈夌殑鏈堜唤宸茬粡鍑嗗濂�
//            //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);
            // 鑾峰彇寮�濮嬪勾浠藉拰寮�濮嬫湀浠�
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH);
            // 鑾峰彇缁撴潫骞翠唤鍜岀粨鏉熸湀浠�
            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);
                        }
                    }

                }

            }

//            // 鎵�鏈夌殑鏈堜唤宸茬粡鍑嗗濂�
//            //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("AAAAAAAAAAAAAAAAAAA");
        }else{
            System.out.println("BBBBBBBBBBBBBB");
        }



    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值