码迷,mamicode.com
首页 > 编程语言 > 详细

Java 如何判定当前时间是否在某个范围

时间:2019-08-30 14:41:11      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:lenovo   爱国   mda   discount   家电   ini   sel   url   exce   

由于一些特别的原因  需要判定当前时间是否在某个特定的范围  

以下是一个根据数据库里面规定的日期选择是否打折,以及打几折的一个DEMO

技术图片
  1 /*
  2  Navicat Premium Data Transfer
  3 
  4  Source Server         : localhost_3306
  5  Source Server Type    : MySQL
  6  Source Server Version : 80017
  7  Source Host           : localhost:3306
  8  Source Schema         : shop
  9 
 10  Target Server Type    : MySQL
 11  Target Server Version : 80017
 12  File Encoding         : 65001
 13 
 14  Date: 30/08/2019 11:48:48
 15 */
 16 
 17 SET NAMES utf8mb4;
 18 SET FOREIGN_KEY_CHECKS = 0;
 19 
 20 -- ----------------------------
 21 -- Table structure for activity
 22 -- ----------------------------
 23 DROP TABLE IF EXISTS `activity`;
 24 CREATE TABLE `activity`  (
 25   `activityId` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 活动编号,
 26   `activityName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 活动名称,
 27   `begin` datetime(0) NOT NULL COMMENT 开始时间,
 28   `finish` datetime(0) NOT NULL COMMENT 结束时间,
 29   `discount` decimal(5, 2) UNSIGNED NOT NULL COMMENT 折扣,
 30   PRIMARY KEY (`activityId`) USING BTREE
 31 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
 32 
 33 -- ----------------------------
 34 -- Records of activity
 35 -- ----------------------------
 36 INSERT INTO `activity` VALUES (1, 双十一, 2019-11-11 00:00:00, 2019-11-11 23:23:59, 0.95);
 37 INSERT INTO `activity` VALUES (2, 618, 2019-06-18 00:00:00, 2019-06-18 23:59:59, 0.95);
 38 INSERT INTO `activity` VALUES (3, 今天, 2019-08-30 00:00:00, 2019-08-30 23:59:59, 0.80);
 39 
 40 -- ----------------------------
 41 -- Table structure for cart
 42 -- ----------------------------
 43 DROP TABLE IF EXISTS `cart`;
 44 CREATE TABLE `cart`  (
 45   `userId` int(11) NOT NULL DEFAULT 0 COMMENT 用户id,
 46   `c_id` int(11) NOT NULL COMMENT 商品id,
 47   `camount` int(15) NOT NULL COMMENT 商品数量
 48 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
 49 
 50 -- ----------------------------
 51 -- Records of cart
 52 -- ----------------------------
 53 INSERT INTO `cart` VALUES (1, 3, 0);
 54 INSERT INTO `cart` VALUES (2, 2, 0);
 55 INSERT INTO `cart` VALUES (1, 2, 0);
 56 INSERT INTO `cart` VALUES (1, 3, 0);
 57 INSERT INTO `cart` VALUES (1, 7, 0);
 58 INSERT INTO `cart` VALUES (1, 1, 0);
 59 INSERT INTO `cart` VALUES (1, 3, 0);
 60 INSERT INTO `cart` VALUES (1, 16, 0);
 61 
 62 -- ----------------------------
 63 -- Table structure for classify
 64 -- ----------------------------
 65 DROP TABLE IF EXISTS `classify`;
 66 CREATE TABLE `classify`  (
 67   `classify_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 商品类型id,
 68   `classify_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 商品类型名称,
 69   PRIMARY KEY (`classify_id`) USING BTREE
 70 ) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
 71 
 72 -- ----------------------------
 73 -- Records of classify
 74 -- ----------------------------
 75 INSERT INTO `classify` VALUES (1, 手机);
 76 INSERT INTO `classify` VALUES (2, 电脑);
 77 INSERT INTO `classify` VALUES (3, 键盘);
 78 INSERT INTO `classify` VALUES (4, 鼠标);
 79 INSERT INTO `classify` VALUES (5, 平板);
 80 INSERT INTO `classify` VALUES (6, 耳机);
 81 INSERT INTO `classify` VALUES (7, 无线充电器);
 82 INSERT INTO `classify` VALUES (8, 皮带);
 83 INSERT INTO `classify` VALUES (9, 刮胡刀);
 84 INSERT INTO `classify` VALUES (10, 音响);
 85 INSERT INTO `classify` VALUES (11, 打火机);
 86 INSERT INTO `classify` VALUES (12, 手表);
 87 INSERT INTO `classify` VALUES (13, 手环);
 88 INSERT INTO `classify` VALUES (14, 硬盘);
 89 INSERT INTO `classify` VALUES (15, U盘);
 90 INSERT INTO `classify` VALUES (16, 路由器);
 91 
 92 -- ----------------------------
 93 -- Table structure for commodity
 94 -- ----------------------------
 95 DROP TABLE IF EXISTS `commodity`;
 96 CREATE TABLE `commodity`  (
 97   `c_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 商品id,
 98   `classify_id` int(11) NOT NULL COMMENT 商品类型,
 99   `c_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 商品名,
100   `price` double(50, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT 价格,
101   `sales` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 销量,
102   `inventory` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 库存,
103   PRIMARY KEY (`c_id`) USING BTREE
104 ) ENGINE = InnoDB AUTO_INCREMENT = 106 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
105 
106 -- ----------------------------
107 -- Records of commodity
108 -- ----------------------------
109 INSERT INTO `commodity` VALUES (1, 0, 小米5S, 2999.00, 51, 99);
110 INSERT INTO `commodity` VALUES (2, 0, dgfd , 34.00, 50, 100);
111 INSERT INTO `commodity` VALUES (3, 0, fdgh, 456.70, 50, 100);
112 INSERT INTO `commodity` VALUES (6, 1, 苹果 xr, 5888.00, 16666, 5822);
113 INSERT INTO `commodity` VALUES (7, 1, 苹果 8Plus, 4988.00, 15661, 1789);
114 INSERT INTO `commodity` VALUES (8, 1, 华为 P30pro, 4988.00, 8099, 2796);
115 INSERT INTO `commodity` VALUES (9, 1, 华为 mate20, 4499.00, 7933, 1988);
116 INSERT INTO `commodity` VALUES (10, 1, VIVO/步步高 iqoo5g, 3198.00, 1759, 2124);
117 INSERT INTO `commodity` VALUES (11, 2, Lenovo/联想 Y7000酷, 6399.00, 243, 2451);
118 INSERT INTO `commodity` VALUES (12, 2, Apple/苹果 MacBook Air, 8099.00, 1700, 1238);
119 INSERT INTO `commodity` VALUES (13, 2, Huawei/华为 MateBook X Pro, 7999.00, 1060, 2541);
120 INSERT INTO `commodity` VALUES (14, 2, Hasee/神州 战神i7 GTX1600Ti, 6999.00, 2191, 1447);
121 INSERT INTO `commodity` VALUES (15, 2, Dell/戴尔 GTX1650 , 5698.00, 1820, 2143);
122 INSERT INTO `commodity` VALUES (16, 2, HP/惠普 暗影精灵5/光影精灵5, 5799.00, 1775, 1789);
123 INSERT INTO `commodity` VALUES (17, 2, Asus/华硕 灵耀S2代s4300FN8代, 4899.00, 1144, 541);
124 INSERT INTO `commodity` VALUES (18, 2, Asus/华硕 X505 超薄, 2999.00, 1019, 275);
125 INSERT INTO `commodity` VALUES (19, 2, Dell/戴尔 5584—灵越酷睿8代i5-8265U, 3999.00, 1000, 1423);
126 INSERT INTO `commodity` VALUES (20, 2, 小米笔记本 RedmiBook i5, 4299.00, 980, 2564);
127 INSERT INTO `commodity` VALUES (21, 3, FLICO/斐尔可 机械键盘 104键, 969.00, 191, 1582);
128 INSERT INTO `commodity` VALUES (22, 3, FLICO/斐尔可 机械键盘 87键, 869.00, 165, 1741);
129 INSERT INTO `commodity` VALUES (23, 3, Keycool/凯酷 87键蓝牙机械键盘, 369.00, 114, 1470);
130 INSERT INTO `commodity` VALUES (24, 3, IQUNX F60蓝牙双模机械键盘cherry轴, 599.00, 147, 1252);
131 INSERT INTO `commodity` VALUES (25, 3, IQUNX F96JOKER蓝牙双模机械键盘, 0.00, 0, 0);
132 INSERT INTO `commodity` VALUES (26, 3, IQUNX F96JOKER蓝牙双模机械键盘, 1288.00, 472, 1527);
133 INSERT INTO `commodity` VALUES (27, 3, IQUNX PINK粉机械键盘F96, 1099.00, 143, 1472);
134 INSERT INTO `commodity` VALUES (28, 3, ANNE/安妮 ANNE pro蓝牙机械键盘, 499.00, 536, 89);
135 INSERT INTO `commodity` VALUES (29, 3, varmiluo/阿米洛 87Mac机械键盘, 699.00, 165, 477);
136 INSERT INTO `commodity` VALUES (30, 3, varmiluo/阿米洛 双模机械键盘海韵静电荣轴, 729.00, 836, 1247);
137 INSERT INTO `commodity` VALUES (31, 4, 罗技 G102有线电竞游戏鼠标, 109.00, 12000, 5622);
138 INSERT INTO `commodity` VALUES (32, 4, 罗技 G502RGB有线鼠标, 279.00, 286, 452);
139 INSERT INTO `commodity` VALUES (33, 4, 罗技 G502无线游戏鼠标, 1099.00, 233, 1436);
140 INSERT INTO `commodity` VALUES (34, 4, Razer/雷蛇 炼狱蝰蛇游戏鼠标专用, 129.00, 13000, 8000);
141 INSERT INTO `commodity` VALUES (35, 4, Razer/雷蛇 蝮蛇竞技版鼠标, 379.00, 445, 1899);
142 INSERT INTO `commodity` VALUES (36, 4, 赛睿/rival 电竞游戏鼠标, 179.00, 459, 124);
143 INSERT INTO `commodity` VALUES (37, 4, 双飞燕 血手幽灵游戏鼠标, 169.00, 1636, 1494);
144 INSERT INTO `commodity` VALUES (38, 4, 雷柏 MT750S蓝牙无线鼠标, 179.00, 933, 1522);
145 INSERT INTO `commodity` VALUES (39, 4, 小米 无线游戏鼠标, 229.00, 136, 147);
146 INSERT INTO `commodity` VALUES (40, 4, 雷柏 VT950无线游戏鼠标, 329.00, 68, 23);
147 INSERT INTO `commodity` VALUES (41, 5, Huawei/华为 M6, 2699.00, 14000, 27555);
148 INSERT INTO `commodity` VALUES (42, 5, Huawei/华为 M5青春版, 1199.00, 3632, 2895);
149 INSERT INTO `commodity` VALUES (43, 5, Apple/苹果 ipad 2018款Air, 3869.00, 6203, 785);
150 INSERT INTO `commodity` VALUES (44, 5, Xiaomi/小米 小米平板2, 369.00, 10, 1477);
151 INSERT INTO `commodity` VALUES (45, 5, Apple/苹果 ipadmini5 , 2258.00, 1346, 2658);
152 INSERT INTO `commodity` VALUES (46, 5, Apple/苹果 ipad Pro 11, 3608.00, 1052, 2588);
153 INSERT INTO `commodity` VALUES (47, 5, 荣耀 荣耀平板5, 1199.00, 630, 253);
154 INSERT INTO `commodity` VALUES (48, 5, Jumper/中柏 EZpad GO, 1849.00, 253, 2147);
155 INSERT INTO `commodity` VALUES (49, 5, Huawei/华为 华为畅享平板m6, 1138.00, 125, 1473);
156 INSERT INTO `commodity` VALUES (50, 5, 小米 小米平板4, 1099.00, 2496, 124);
157 INSERT INTO `commodity` VALUES (51, 6, 三星AKG 原装耳机note8, 35.00, 3216, 1489);
158 INSERT INTO `commodity` VALUES (52, 6, 苹果 原装耳机3.5mm, 189.00, 1814, 50458);
159 INSERT INTO `commodity` VALUES (53, 6, 苹果原装耳机 Lightning接口, 189.00, 9607, 48953);
160 INSERT INTO `commodity` VALUES (54, 6, 苹果 AirPods, 1246.00, 77000, 84000);
161 INSERT INTO `commodity` VALUES (55, 6, Beats solo3 wireless无线蓝牙耳机, 678.00, 2900, 2685);
162 INSERT INTO `commodity` VALUES (56, 6, Beats BeatsX 耳塞无线蓝牙耳机, 799.00, 1988, 8412);
163 INSERT INTO `commodity` VALUES (57, 6, Beats BeatsURBEATS3.0魔音, 486.00, 982, 1455);
164 INSERT INTO `commodity` VALUES (58, 6, VIVO vivoX21原装耳机, 68.00, 438, 1989);
165 INSERT INTO `commodity` VALUES (59, 6, VIVO vivoXE100, 36.00, 152, 986);
166 INSERT INTO `commodity` VALUES (60, 6, OPPO MH135, 59.00, 13000, 14007);
167 INSERT INTO `commodity` VALUES (61, 7, 紫米/zimi 紫米无线充电器, 99.00, 586, 12777);
168 INSERT INTO `commodity` VALUES (62, 8, 卓凡 阿尼玛皮带, 158.00, 7402, 2895);
169 INSERT INTO `commodity` VALUES (63, 8, 花花公子皮带, 49.00, 18000, 28914);
170 INSERT INTO `commodity` VALUES (64, 8, 稻草人皮带, 59.00, 24000, 14755);
171 INSERT INTO `commodity` VALUES (65, 8, 七匹狼皮带, 129.00, 581, 2514);
172 INSERT INTO `commodity` VALUES (66, 8, 金利来皮带, 259.00, 5427, 3615);
173 INSERT INTO `commodity` VALUES (67, 9, 博朗剃须刀, 899.00, 3758, 4815);
174 INSERT INTO `commodity` VALUES (68, 9, 飞科剃须刀, 59.00, 12045, 58411);
175 INSERT INTO `commodity` VALUES (69, 9, 小米剃须刀, 79.00, 6038, 14855);
176 INSERT INTO `commodity` VALUES (70, 9, 飞利浦剃须刀, 229.00, 52000, 14772);
177 INSERT INTO `commodity` VALUES (71, 10, EARISE/雅兰仕 H2笔记本音响, 8.90, 50955, 14751);
178 INSERT INTO `commodity` VALUES (72, 10, 小米小艾音响, 99.00, 26140, 4715);
179 INSERT INTO `commodity` VALUES (73, 10, 天猫精灵音响, 89.00, 41504, 12483);
180 INSERT INTO `commodity` VALUES (74, 11, zippo打火机, 150.00, 3435, 28456);
181 INSERT INTO `commodity` VALUES (75, 11, ZORRO煤油打火机, 37.00, 6911, 1477);
182 INSERT INTO `commodity` VALUES (76, 11, Cricket草蜢打火机, 21.90, 2031, 4511);
183 INSERT INTO `commodity` VALUES (77, 12, 天王手表GS31091, 949.00, 1457, 12487);
184 INSERT INTO `commodity` VALUES (78, 12, 罗西尼MTP-1375, 398.00, 3654, 14784);
185 INSERT INTO `commodity` VALUES (79, 12, 卡西欧防水钢表, 388.00, 2444, 12487);
186 INSERT INTO `commodity` VALUES (80, 12, 依波机自动机械表, 1169.00, 14557, 21478);
187 INSERT INTO `commodity` VALUES (81, 12, 飞亚达女表钢带, 520.00, 1245, 14552);
188 INSERT INTO `commodity` VALUES (82, 13, 小米手环4, 169.00, 14553, 48551);
189 INSERT INTO `commodity` VALUES (83, 13, 华为荣耀手环, 219.00, 48751, 95441);
190 INSERT INTO `commodity` VALUES (84, 14, 希捷高速USB3.0移动2T, 499.00, 1884, 14745);
191 INSERT INTO `commodity` VALUES (85, 14, 希捷高速USB3.0移动1T, 355.00, 3309, 15843);
192 INSERT INTO `commodity` VALUES (86, 14, 东芝Usb3.0移动1T, 329.00, 4184, 12452);
193 INSERT INTO `commodity` VALUES (87, 14, 纽曼移动硬盘2T, 79.00, 13000, 25482);
194 INSERT INTO `commodity` VALUES (88, 14, 西部数据USB3.0高速移动银盘1T, 288.60, 1423, 4854);
195 INSERT INTO `commodity` VALUES (89, 14, 蓝硕USB3.0移动硬盘500g, 55.00, 460, 2841);
196 INSERT INTO `commodity` VALUES (90, 15, 惠普U盘32g, 29.00, 1550, 4812);
197 INSERT INTO `commodity` VALUES (91, 15, 三星U盘32g, 70.00, 10, 551);
198 INSERT INTO `commodity` VALUES (92, 15, 金士顿16g, 31.90, 1363, 4851);
199 INSERT INTO `commodity` VALUES (93, 15, 夏科U盘256gUSB3.0, 149.00, 1478, 15473);
200 INSERT INTO `commodity` VALUES (94, 15, 爱国者U盘32g, 32.90, 33007, 48451);
201 INSERT INTO `commodity` VALUES (95, 15, 闪迪U盘64g, 59.90, 18236, 25412);
202 INSERT INTO `commodity` VALUES (96, 16, 腾达 AC10千兆路由器, 129.00, 17596, 57441);
203 INSERT INTO `commodity` VALUES (97, 16, 小米4C智能路由器, 69.00, 6216, 18457);
204 INSERT INTO `commodity` VALUES (98, 16, 水星D196 1900M无线路由器, 135.00, 48125, 58458);
205 INSERT INTO `commodity` VALUES (99, 16, 荣耀路由器双千兆, 329.00, 3974, 28485);
206 INSERT INTO `commodity` VALUES (100, 16, 华为路由器, 139.00, 4771, 14784);
207 INSERT INTO `commodity` VALUES (101, 16, 华为路由器, 139.00, 4771, 14784);
208 INSERT INTO `commodity` VALUES (102, 1, 小米8青春版, 1039.00, 1802, 224);
209 INSERT INTO `commodity` VALUES (103, 1, 小米8手机屏幕指纹版, 1499.00, 1988, 166);
210 INSERT INTO `commodity` VALUES (104, 1, 小米9se, 1749.00, 1007, 667);
211 INSERT INTO `commodity` VALUES (105, 1, 苹果 xsmax, 9888.00, 9997, 4000);
212 INSERT INTO `commodity` VALUES (106, 1, 苹果 xs, 8888.00, 9856, 3410);
213 
214 -- ----------------------------
215 -- Table structure for record
216 -- ----------------------------
217 DROP TABLE IF EXISTS `record`;
218 CREATE TABLE `record`  (
219   `userId` int(11) NOT NULL COMMENT 用户id,
220   `r_id` int(11) NOT NULL COMMENT 记录用户操作类型编号,
221   `r_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 记录用户操作类型名称,
222   `time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT 记录用户操作类型时间,
223   `c_id` int(11) NOT NULL COMMENT 商品id
224 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
225 
226 -- ----------------------------
227 -- Table structure for seller
228 -- ----------------------------
229 DROP TABLE IF EXISTS `seller`;
230 CREATE TABLE `seller`  (
231   `seller_id` int(10) NOT NULL AUTO_INCREMENT COMMENT 卖家编号,
232   `seller_name` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 卖家姓名,
233   `seller_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 卖家地址,
234   `seller_password` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 卖家密码,
235   `seller_balance` decimal(65, 2) UNSIGNED NOT NULL COMMENT 卖家余额,
236   `seller_phone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 卖家电话号码,
237   PRIMARY KEY (`seller_id`) USING BTREE
238 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
239 
240 -- ----------------------------
241 -- Records of seller
242 -- ----------------------------
243 INSERT INTO `seller` VALUES (1, akb48, 黄泉路52号, 123456, 10355.00, 13444444444);
244 
245 -- ----------------------------
246 -- Table structure for states
247 -- ----------------------------
248 DROP TABLE IF EXISTS `states`;
249 CREATE TABLE `states`  (
250   `userId` int(11) NOT NULL DEFAULT 0 COMMENT 用户id,
251   `c_id` int(11) NOT NULL DEFAULT 0 COMMENT 商品id,
252   `states_id` int(11) NOT NULL DEFAULT 0 COMMENT 状态id,
253   `evaluation` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 已上架 COMMENT 商品评价,
254   INDEX `fk_user_commodity`(`userId`) USING BTREE
255 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
256 
257 -- ----------------------------
258 -- Table structure for user
259 -- ----------------------------
260 DROP TABLE IF EXISTS `user`;
261 CREATE TABLE `user`  (
262   `userId` int(11) NOT NULL AUTO_INCREMENT COMMENT 用户ID,
263   `userName` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 用户名,
264   `password` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 123456 COMMENT 密码,
265   `user_balance` double(50, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT 余额,
266   `integrate` double(50, 2) UNSIGNED NOT NULL DEFAULT 100.00 COMMENT 积分,
267   `address` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 未填写 COMMENT 地址,
268   `email` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 未添加 COMMENT 邮箱++做密保,
269   `sex` int(1) NOT NULL DEFAULT 0 COMMENT 0表示男,1表示女,
270   `user_phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 买家电话号码,
271   PRIMARY KEY (`userId`) USING BTREE,
272   UNIQUE INDEX `userName`(`userName`) USING BTREE,
273   UNIQUE INDEX `email`(`email`) USING BTREE
274 ) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
275 
276 -- ----------------------------
277 -- Records of user
278 -- ----------------------------
279 INSERT INTO `user` VALUES (1, agdgdfg, 123456, 4545.00, 100.00, 未填写, 未添加, 0, ‘‘);
280 
281 SET FOREIGN_KEY_CHECKS = 1;
对应数据库
技术图片
  1 package com.shop.impl;
  2 
  3 import com.shop.util.ConfigManager;
  4 import com.shop.util.Get;
  5 
  6 import java.sql.*;
  7 
  8 import com.shop.pojo.States;
  9 
 10 public class BaseDao {
 11     PreparedStatement ps = null;
 12     ResultSet rs = null;
 13     Connection conn = null;
 14     private final String driver = ConfigManager.getInstance().getString("jdbc.driver");
 15     private final String url = ConfigManager.getInstance().getString("jdbc.url");
 16     private final String user = ConfigManager.getInstance().getString("jdbc.userName");
 17     private final String password = ConfigManager.getInstance().getString("jdbc.password");
 18 
 19     /**
 20      * 获取数据库连接
 21      */
 22     public Connection getConn() {
 23         try {
 24             Class.forName(driver);
 25             conn = DriverManager.getConnection(url, user, password);
 26 //            System.out.println(conn);
 27         } catch (ClassNotFoundException e) {
 28             e.printStackTrace();
 29         } catch (SQLException e) {
 30             e.printStackTrace();
 31         }
 32         return conn;
 33     }
 34 
 35     /**
 36      * 查询方法
 37      *
 38      * @param sql
 39      * @param obj
 40      * @return
 41      */
 42     public ResultSet executeQuery(String sql, Object... obj) {
 43         getConn();
 44         try {
 45             ps = conn.prepareStatement(sql);
 46             if (obj != null) {
 47                 for (int i = 0; i < obj.length; i++) {
 48                     ps.setObject((i + 1), obj[i]);
 49                 }
 50             }
 51             rs = ps.executeQuery();
 52         } catch (SQLException e) {
 53             e.printStackTrace();
 54         }
 55         return rs;
 56 
 57     }
 58 
 59     /**
 60      * 更新方法
 61      *
 62      * @param sql
 63      * @param obj
 64      * @return
 65      */
 66     public int executeUpdate(String sql, Object... obj) {
 67         getConn();
 68         int result = 0;
 69         try {
 70             ps = conn.prepareStatement(sql);
 71             if (obj != null) {
 72                 for (int i = 0; i < obj.length; i++) {
 73                     ps.setObject((i + 1), obj[i]);
 74                 }
 75                 try{result = ps.executeUpdate();}catch (Exception e){
 76                     System.out.println("操作失误!");
 77                 }
 78             }
 79         } catch (SQLIntegrityConstraintViolationException e) {
 80 
 81         } catch (SQLException e) {
 82             e.printStackTrace();
 83         } finally {
 84             closeAll();
 85         }
 86         return result;
 87     }
 88 
 89     /**
 90      * 释放资源
 91      */
 92     public void closeAll() {
 93         try {
 94             if (rs != null) {
 95                 rs.close();
 96             }
 97             if (ps != null) {
 98                 ps.close();
 99             }
100             if (conn != null) {
101                 conn.close();
102             }
103         } catch (SQLException e) {
104             e.printStackTrace();
105         }
106     }
107 
108 }
BaseDao
技术图片
 1 package com.shop.util;
 2 
 3 import com.shop.impl.ActivityDaoImpl;
 4 
 5 import java.text.ParseException;
 6 import java.text.SimpleDateFormat;
 7 import java.util.*;
 8 
 9 /**
10  * @auther::9527
11  * @Description: 活动,根据日期判定是否在购买时进行优惠
12  * @program: jdbc_demo
13  * @create: 2019-08-30 08:50
14  */
15 public class Discount {
16 
17     /**
18      * @param nowTime   当前时间
19      * @param beginTime 开始时间
20      * @param endTime   结束时间
21      * @return 如果当前时间在开始时间和结束时间之内就返回true,否则返回false
22      * @author 周小龙  19-8-30
23      */
24     public static boolean isActivity(Date nowTime, Date beginTime, Date endTime) {
25         Calendar date = Calendar.getInstance();
26         date.setTime(nowTime);
27         Calendar begin = Calendar.getInstance();
28         begin.setTime(beginTime);
29         Calendar end = Calendar.getInstance();
30         end.setTime(endTime);
31         if (date.after(begin) && date.before(end)) {
32             return true;
33         } else if (nowTime.compareTo(beginTime) == 0 || nowTime.compareTo(endTime) == 0) {
34             return true;
35         } else {
36             return false;
37         }
38     }
39 
40     /**
41      * @param str 按格式输入时间
42      * @return 根据String返回时间
43      */
44     public static Date strToDate(String str) {
45         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
46         Date date = null;
47         try {
48             date = sdf.parse(str);
49         } catch (ParseException e) {
50         }
51         return date;
52     }
53 
54 
55     /**
56      * @param map 传递活动名称,开始时间,结束时间,和折扣的map
57      * @return 返回折扣系数
58      */
59     public static double isDiscount(Map<String, Map<Map<String, String>, Double>> map) {
60         double discount = 1.0;
61 
62         for (Map.Entry<String, Map<Map<String, String>, Double>> waiCeng : map.entrySet()) {
63             for (Map.Entry<Map<String, String>, Double> zhongCeng : waiCeng.getValue().entrySet()) {
64                 for (Map.Entry<String, String> neiCeng : zhongCeng.getKey().entrySet()) {
65                     if (isActivity(new Date(), strToDate(neiCeng.getKey()), strToDate(neiCeng.getValue()))) {
66                         for (Map.Entry<String, Map<Map<String, String>, Double>> waiCeng1 : map.entrySet()) {
67                             for (Map.Entry<Map<String, String>, Double> zhongCeng1 : waiCeng1.getValue().entrySet()) {
68                                 discount = zhongCeng1.getValue();
69                             }
70                         }
71                     }
72                 }
73             }
74         }
75         return discount;
76     }
77 
78 
79     //测试
80     public static void main(String[] args) {
81         ActivityDaoImpl activityDao = new ActivityDaoImpl();
82         Map<String, Map<Map<String, String>, Double>> map = activityDao.findAll();
83         double di = isDiscount(map);
84         System.out.println(di);
85     }
86 }
判定当前日期是否在某个范围的类
技术图片
 1 package com.shop.impl;
 2 
 3 import com.shop.dao.ActivityDao;
 4 import com.shop.pojo.Activity;
 5 
 6 import java.sql.SQLException;
 7 import java.util.*;
 8 
 9 /**
10  * @auther::9527
11  * @Description: 活动实现类
12  * @program: jdbc_demo
13  * @create: 2019-08-30 10:37
14  */
15 public class ActivityDaoImpl extends BaseDao implements ActivityDao {
16     /**
17      * @param activityName
18      * @return
19      * @author 周小龙
20      */
21     @Override
22     public Activity findByName(String activityName) {
23         return null;
24     }
25 
26     /**
27      * @param
28      * @return
29      * @author 周小龙
30      */
31     @Override
32     public Map<String, Map<Map<String, String>, Double>> findAll() {
33         Map<String, Map<Map<String, String>, Double>> mapOut = null;
34         Map<Map<String, String>, Double> mapMid = new HashMap<>();
35         Map<String, String> mapIn = new HashMap<>();
36 
37         com.shop.pojo.Activity activity = null;
38         String sql = "SELECT * from activity";
39         Object[] obj = {};
40         rs = this.executeQuery(sql, obj);
41         try {
42             while (rs.next()) {
43                 mapOut = new HashMap<>();
44                 mapMid = new HashMap<>();
45                 mapIn = new HashMap<>();
46                 activity = new com.shop.pojo.Activity();
47                 activity.setActivityId(rs.getInt("activityId"));
48                 activity.setActivityName(rs.getString("activityName"));
49                 activity.setBegin(rs.getString("begin"));
50                 activity.setFinish(rs.getString("finish"));
51                 activity.setDiscount(rs.getDouble("discount"));
52                 //传递活动名称,开始时间,结束时间,和折扣
53                 String name = activity.getActivityName();
54                 String begin = activity.getBegin();
55                 String finish = activity.getFinish();
56                 double discount = activity.getDiscount();
57                 mapIn.put(begin, finish);
58                 mapMid.put(mapIn, discount);
59                 mapOut.put(name, mapMid);
60             }
61 
62 
63         } catch (SQLException e) {
64             e.printStackTrace();
65         }
66         return mapOut;
67     }
68 
69 
70 
71     public static void main(String[] args) {
72         ActivityDaoImpl activityDao = new ActivityDaoImpl();
73 
74     }
75 }
操作数据库的实现类
技术图片
 1 package com.shop.dao;
 2 
 3 import com.shop.pojo.Activity;
 4 
 5 import java.util.Map;
 6 
 7 /**
 8  * @auther::9527
 9  * @Description: 活动接口
10  * @program: jdbc_demo
11  * @create: 2019-08-30 10:37
12  */
13 public interface ActivityDao {
14     /**
15      * @author 周小龙
16      * @param activityName
17      * @return
18      */
19     Activity findByName(String activityName);
20 
21     /**
22      *
23      * @param
24      * @return
25      */
26     Map<String, Map<Map<String, String>, Double>> findAll();
27 
28 }
操作数据库的接口

 

|--关键代码:

技术图片
 1 /**
 2      * @param str 按格式输入时间
 3      * @return 根据String返回时间
 4      */
 5     public static Date strToDate(String str) {
 6         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 7         Date date = null;
 8         try {
 9             date = sdf.parse(str);
10         } catch (ParseException e) {
11         }
12         return date;
13     }
14 
15 /**
16      * @param nowTime   当前时间
17      * @param beginTime 开始时间
18      * @param endTime   结束时间
19      * @return 如果当前时间在开始时间和结束时间之内就返回true,否则返回false
20      * @author 周小龙  19-8-30
21      */
22     public static boolean isActivity(Date nowTime, Date beginTime, Date endTime) {
23         Calendar date = Calendar.getInstance();
24         date.setTime(nowTime);
25         Calendar begin = Calendar.getInstance();
26         begin.setTime(beginTime);
27         Calendar end = Calendar.getInstance();
28         end.setTime(endTime);
29         if (date.after(begin) && date.before(end)) {
30             return true;
31         } else if (nowTime.compareTo(beginTime) == 0 || nowTime.compareTo(endTime) == 0) {
32             return true;
33         } else {
34             return false;
35         }
36     }
View Code

 

Java 如何判定当前时间是否在某个范围

标签:lenovo   爱国   mda   discount   家电   ini   sel   url   exce   

原文地址:https://www.cnblogs.com/twuxian/p/11434339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!