com.ruoyi.common.utils.DateUtils Java Examples
The following examples show how to use
com.ruoyi.common.utils.DateUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenUtils.java From ruoyiplus with MIT License | 6 votes |
/** * 获取模板信息 * * @return 模板列表 */ public static VelocityContext getVelocityContext(TableInfo table,String _packageName) { // java对象数据传递到模板文件vm VelocityContext velocityContext = new VelocityContext(); String packageName = _packageName==null?Global.getPackageName():_packageName; velocityContext.put("tableName", table.getTableName()); velocityContext.put("tableComment", replaceKeyword(table.getTableComment())); velocityContext.put("primaryKey", table.getPrimaryKey()); velocityContext.put("className", table.getClassName()); velocityContext.put("classname", table.getClassname()); velocityContext.put("moduleName", getModuleName(packageName)); velocityContext.put("columns", table.getColumns()); velocityContext.put("basePackage", getBasePackage(packageName)); velocityContext.put("package", packageName); velocityContext.put("author", Convert.toStr(Global.getAuthor(),"cxlh")); velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("module", StrUtil.isEmpty(table.getModule())?getModuleName(packageName):table.getModule()); velocityContext.put("uri",table.getUri()); velocityContext.put("dir",table.getBaseDir()); velocityContext.put("tmpl",table.getWebTempleName()); return velocityContext; }
Example #2
Source File: DemoTableController.java From supplierShop with MIT License | 5 votes |
public UserTableModel(int userId, String userCode, String userName, String userSex, String userPhone, String userEmail, double userBalance, String status) { this.userId = userId; this.userCode = userCode; this.userName = userName; this.userSex = userSex; this.userPhone = userPhone; this.userEmail = userEmail; this.userBalance = userBalance; this.status = status; this.createTime = DateUtils.getNowDate(); }
Example #3
Source File: BaseController.java From ruoyiplus with MIT License | 5 votes |
/** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder public void initBinder(WebDataBinder binder) { // Date 类型转换 binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); }
Example #4
Source File: SysLoginService.java From ruoyiplus with MIT License | 5 votes |
/** * 记录登录信息 */ public void recordLoginInfo(SysUser user) { user.setLoginIp(ShiroUtils.getIp()); user.setLoginDate(DateUtils.getNowDate()); userService.updateUserInfo(user); }
Example #5
Source File: BaseController.java From RuoYi-Vue with MIT License | 5 votes |
/** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder public void initBinder(WebDataBinder binder) { // Date 类型转换 binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); }
Example #6
Source File: ExcelUtil.java From RuoYi-Vue with MIT License | 5 votes |
/** * 添加单元格 */ public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { Cell cell = null; try { // 设置行高 row.setHeight((short) (attr.height() * 20)); // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. if (attr.isExport()) { // 创建cell cell = row.createCell(column); cell.setCellStyle(styles.get("data")); // 用于读取对象中的属性 Object value = getTargetValue(vo, field, attr); String dateFormat = attr.dateFormat(); String readConverterExp = attr.readConverterExp(); if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) { cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); } else { // 设置列类型 setCellVo(value, attr, cell); } } } catch (Exception e) { log.error("导出Excel失败{}", e); } return cell; }
Example #7
Source File: FileUploadUtils.java From RuoYi-Vue with MIT License | 5 votes |
/** * 编码文件名 */ public static final String extractFilename(MultipartFile file) { String fileName = file.getOriginalFilename(); String extension = getExtension(file); fileName = DateUtils.datePath() + "/" + encodingFilename(fileName) + "." + extension; return fileName; }
Example #8
Source File: VelocityUtils.java From supplierShop with MIT License | 5 votes |
/** * 设置模板变量信息 * * @return 模板列表 */ public static VelocityContext prepareContext(GenTable genTable) { String moduleName = genTable.getModuleName(); String businessName = genTable.getBusinessName(); String packageName = genTable.getPackageName(); String tplCategory = genTable.getTplCategory(); String functionName = genTable.getFunctionName(); VelocityContext velocityContext = new VelocityContext(); velocityContext.put("tplCategory", genTable.getTplCategory()); velocityContext.put("tableName", genTable.getTableName()); velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); velocityContext.put("ClassName", genTable.getClassName()); velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); velocityContext.put("moduleName", genTable.getModuleName()); velocityContext.put("businessName", genTable.getBusinessName()); velocityContext.put("basePackage", getPackagePrefix(packageName)); velocityContext.put("packageName", packageName); velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("pkColumn", genTable.getPkColumn()); velocityContext.put("importList", getImportList(genTable.getColumns())); velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { setTreeVelocityContext(velocityContext, genTable); } return velocityContext; }
Example #9
Source File: VelocityUtils.java From RuoYi-Vue with MIT License | 5 votes |
/** * 设置模板变量信息 * * @return 模板列表 */ public static VelocityContext prepareContext(GenTable genTable) { String moduleName = genTable.getModuleName(); String businessName = genTable.getBusinessName(); String packageName = genTable.getPackageName(); String tplCategory = genTable.getTplCategory(); String functionName = genTable.getFunctionName(); VelocityContext velocityContext = new VelocityContext(); velocityContext.put("tplCategory", genTable.getTplCategory()); velocityContext.put("tableName", genTable.getTableName()); velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); velocityContext.put("ClassName", genTable.getClassName()); velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); velocityContext.put("moduleName", genTable.getModuleName()); velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); velocityContext.put("businessName", genTable.getBusinessName()); velocityContext.put("basePackage", getPackagePrefix(packageName)); velocityContext.put("packageName", packageName); velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("pkColumn", genTable.getPkColumn()); velocityContext.put("importList", getImportList(genTable.getColumns())); velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { setTreeVelocityContext(velocityContext, genTable); } return velocityContext; }
Example #10
Source File: UserOperateModel.java From supplierShop with MIT License | 5 votes |
public UserOperateModel(int userId, String userCode, String userName, String userSex, String userPhone, String userEmail, double userBalance, String status) { this.userId = userId; this.userCode = userCode; this.userName = userName; this.userSex = userSex; this.userPhone = userPhone; this.userEmail = userEmail; this.userBalance = userBalance; this.status = status; this.createTime = DateUtils.getNowDate(); }
Example #11
Source File: SysUserOnlineServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 查询会话集合 * * @param expiredDate 失效日期 */ @Override public List<SysUserOnline> selectOnlineByExpired(Date expiredDate) { String lastAccessTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, expiredDate); return userOnlineDao.selectOnlineByExpired(lastAccessTime); }
Example #12
Source File: StoreMemberServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 修改商城会员信息 * * @param storeMember 商城会员信息 * @return 结果 */ @Override public int updateStoreMember(StoreMember storeMember) { storeMember.setUpdateTime(DateUtils.getNowDate()); return storeMemberMapper.updateStoreMember(storeMember); }
Example #13
Source File: StoreMemberServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 新增商城会员信息 * * @param storeMember 商城会员信息 * @return 结果 */ @Override public int insertStoreMember(StoreMember storeMember) { storeMember.setCreateTime(DateUtils.getNowDate()); return storeMemberMapper.insertStoreMember(storeMember); }
Example #14
Source File: BaseController.java From supplierShop with MIT License | 5 votes |
/** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder public void initBinder(WebDataBinder binder) { // Date 类型转换 binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); }
Example #15
Source File: ExcelUtil.java From supplierShop with MIT License | 5 votes |
/** * 添加单元格 */ public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { Cell cell = null; try { // 设置行高 row.setHeight((short) (attr.height() * 20)); // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. if (attr.isExport()) { // 创建cell cell = row.createCell(column); cell.setCellStyle(styles.get("data")); // 用于读取对象中的属性 Object value = getTargetValue(vo, field, attr); String dateFormat = attr.dateFormat(); String readConverterExp = attr.readConverterExp(); if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) { cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); } else { // 设置列类型 setCellVo(value, attr, cell); } } } catch (Exception e) { log.error("导出Excel失败{}", e); } return cell; }
Example #16
Source File: FileUploadUtils.java From supplierShop with MIT License | 5 votes |
/** * 编码文件名 */ public static final String extractFilename(MultipartFile file) { String fileName = file.getOriginalFilename(); String extension = getExtension(file); fileName = DateUtils.datePath() + "/" + encodingFilename(fileName) + "." + extension; return fileName; }
Example #17
Source File: SysLoginService.java From supplierShop with MIT License | 5 votes |
/** * 记录登录信息 */ public void recordLoginInfo(SysUser user) { user.setLoginIp(ShiroUtils.getIp()); user.setLoginDate(DateUtils.getNowDate()); userService.updateUserInfo(user); }
Example #18
Source File: SysUserOnlineServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 查询会话集合 * * @param expiredDate 失效日期 */ @Override public List<SysUserOnline> selectOnlineByExpired(Date expiredDate) { String lastAccessTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, expiredDate); return userOnlineDao.selectOnlineByExpired(lastAccessTime); }
Example #19
Source File: ReflectUtils.java From RuoYi-Vue with MIT License | 4 votes |
/** * 直接调用对象方法, 无视private/protected修饰符, * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用. * 只匹配函数名,如果有多个同名函数调用第一个。 */ @SuppressWarnings("unchecked") public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) { Method method = getAccessibleMethodByName(obj, methodName, args.length); if (method == null) { // 如果为空不报错,直接返回空。 logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); return null; } try { // 类型转换(将参数数据类型转换为目标方法参数类型) Class<?>[] cs = method.getParameterTypes(); for (int i = 0; i < cs.length; i++) { if (args[i] != null && !args[i].getClass().equals(cs[i])) { if (cs[i] == String.class) { args[i] = Convert.toStr(args[i]); if (StringUtils.endsWith((String) args[i], ".0")) { args[i] = StringUtils.substringBefore((String) args[i], ".0"); } } else if (cs[i] == Integer.class) { args[i] = Convert.toInt(args[i]); } else if (cs[i] == Long.class) { args[i] = Convert.toLong(args[i]); } else if (cs[i] == Double.class) { args[i] = Convert.toDouble(args[i]); } else if (cs[i] == Float.class) { args[i] = Convert.toFloat(args[i]); } else if (cs[i] == Date.class) { if (args[i] instanceof String) { args[i] = DateUtils.parseDate(args[i]); } else { args[i] = DateUtil.getJavaDate((Double) args[i]); } } } } return (E) method.invoke(obj, args); } catch (Exception e) { String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; throw convertReflectionExceptionToUnchecked(msg, e); } }
Example #20
Source File: ExcelUtil.java From ruoyiplus with MIT License | 4 votes |
/** * 填充excel数据 * * @param index 序号 * @param row 单元格行 * @param cell 类型单元格 */ public void fillExcelData(int index, Row row, Cell cell) { int startNo = index * sheetSize; int endNo = Math.min(startNo + sheetSize, list.size()); // 写入各条记录,每条记录对应excel表中的一行 CellStyle cs = wb.createCellStyle(); cs.setAlignment(HorizontalAlignment.CENTER); cs.setVerticalAlignment(VerticalAlignment.CENTER); for (int i = startNo; i < endNo; i++) { row = sheet.createRow(i + 1 - startNo); // 得到导出对象. T vo = (T) list.get(i); for (int j = 0; j < fields.size(); j++) { // 获得field. Field field = fields.get(j); // 设置实体类私有属性可访问 field.setAccessible(true); Excel attr = field.getAnnotation(Excel.class); try { // 设置行高 row.setHeight((short) (attr.height() * 20)); // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. if (attr.isExport()) { // 创建cell cell = row.createCell(j); cell.setCellStyle(cs); if (vo == null) { // 如果数据存在就填入,不存在填入空格. cell.setCellValue(""); continue; } // 用于读取对象中的属性 Object value = getTargetValue(vo, field, attr); String dateFormat = attr.dateFormat(); String readConverterExp = attr.readConverterExp(); if (StringUtils.isNotEmpty(dateFormat)) { cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); } else if (StringUtils.isNotEmpty(readConverterExp)) { cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); } else { cell.setCellType(CellType.STRING); // 如果数据存在就填入,不存在填入空格. cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix()); } } } catch (Exception e) { log.error("导出Excel失败{}", e.getMessage()); } } } }
Example #21
Source File: Jvm.java From ruoyiplus with MIT License | 4 votes |
/** * JDK运行时间 */ public String getRunTime() { return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate()); }
Example #22
Source File: ReflectUtils.java From ruoyiplus with MIT License | 4 votes |
/** * 直接调用对象方法, 无视private/protected修饰符, * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用. * 只匹配函数名,如果有多个同名函数调用第一个。 */ @SuppressWarnings("unchecked") public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) { Method method = getAccessibleMethodByName(obj, methodName, args.length); if (method == null) { // 如果为空不报错,直接返回空。 logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); return null; } try { // 类型转换(将参数数据类型转换为目标方法参数类型) Class<?>[] cs = method.getParameterTypes(); for (int i = 0; i < cs.length; i++) { if (args[i] != null && !args[i].getClass().equals(cs[i])) { if (cs[i] == String.class) { args[i] = Convert.toStr(args[i]); if (StringUtils.endsWith((String) args[i], ".0")) { args[i] = StringUtils.substringBefore((String) args[i], ".0"); } } else if (cs[i] == Integer.class) { args[i] = Convert.toInt(args[i]); } else if (cs[i] == Long.class) { args[i] = Convert.toLong(args[i]); } else if (cs[i] == Double.class) { args[i] = Convert.toDouble(args[i]); } else if (cs[i] == Float.class) { args[i] = Convert.toFloat(args[i]); } else if (cs[i] == Date.class) { if (args[i] instanceof String) { args[i] = DateUtils.parseDate(args[i]); } else { args[i] = DateUtil.getJavaDate((Double) args[i]); } } } } return (E) method.invoke(obj, args); } catch (Exception e) { String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; throw convertReflectionExceptionToUnchecked(msg, e); } }
Example #23
Source File: Jvm.java From ruoyiplus with MIT License | 4 votes |
/** * JDK启动时间 */ public String getStartTime() { return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate()); }
Example #24
Source File: Jvm.java From RuoYi-Vue with MIT License | 4 votes |
/** * JDK运行时间 */ public String getRunTime() { return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate()); }
Example #25
Source File: Jvm.java From RuoYi-Vue with MIT License | 4 votes |
/** * JDK启动时间 */ public String getStartTime() { return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate()); }
Example #26
Source File: ReflectUtils.java From supplierShop with MIT License | 4 votes |
/** * 直接调用对象方法, 无视private/protected修饰符, * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用. * 只匹配函数名,如果有多个同名函数调用第一个。 */ @SuppressWarnings("unchecked") public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) { Method method = getAccessibleMethodByName(obj, methodName, args.length); if (method == null) { // 如果为空不报错,直接返回空。 logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); return null; } try { // 类型转换(将参数数据类型转换为目标方法参数类型) Class<?>[] cs = method.getParameterTypes(); for (int i = 0; i < cs.length; i++) { if (args[i] != null && !args[i].getClass().equals(cs[i])) { if (cs[i] == String.class) { args[i] = Convert.toStr(args[i]); if (StringUtils.endsWith((String) args[i], ".0")) { args[i] = StringUtils.substringBefore((String) args[i], ".0"); } } else if (cs[i] == Integer.class) { args[i] = Convert.toInt(args[i]); } else if (cs[i] == Long.class) { args[i] = Convert.toLong(args[i]); } else if (cs[i] == Double.class) { args[i] = Convert.toDouble(args[i]); } else if (cs[i] == Float.class) { args[i] = Convert.toFloat(args[i]); } else if (cs[i] == Date.class) { if (args[i] instanceof String) { args[i] = DateUtils.parseDate(args[i]); } else { args[i] = DateUtil.getJavaDate((Double) args[i]); } } } } return (E) method.invoke(obj, args); } catch (Exception e) { String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; throw convertReflectionExceptionToUnchecked(msg, e); } }
Example #27
Source File: Jvm.java From supplierShop with MIT License | 4 votes |
/** * JDK运行时间 */ public String getRunTime() { return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate()); }
Example #28
Source File: Jvm.java From supplierShop with MIT License | 4 votes |
/** * JDK启动时间 */ public String getStartTime() { return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate()); }