Java Code Examples for cn.hutool.core.date.DateUtil#format()

The following examples show how to use cn.hutool.core.date.DateUtil#format() . 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: BackupController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 备份数据库
 *
 * @return 重定向到/admin/backup
 */
public JsonResult backupDatabase() {
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
        }
        final String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
        final String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        //压缩文件
        ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
        log.info("Current time: {}, database backup was performed.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup database failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 2
Source File: BackupController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 备份资源文件 重要
 *
 * @return JsonResult
 */
public JsonResult backupResources() {
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/resources/");
        }
        final File path = new File(ResourceUtils.getURL("classpath:").getPath());
        final String srcPath = path.getAbsolutePath();
        final String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        //执行打包
        ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
        log.info("Current time: {}, the resource file backup was performed.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup resource file failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 3
Source File: BackupController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 备份文章,导出markdown文件
 *
 * @return JsonResult
 */
public JsonResult backupPosts() {
    final List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
    posts.addAll(postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc()));
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
        }
        //打包好的文件名
        final String distName = "posts_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/posts/" + distName;
        for (Post post : posts) {
            HaloUtils.postToFile(post.getPostContentMd(), srcPath, post.getPostTitle() + ".md");
        }
        //打包导出好的文章
        ZipUtil.zip(srcPath, srcPath + ".zip");
        FileUtil.del(srcPath);
        log.info("Current time: {}, performed an article backup.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup article failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 4
Source File: AttachFileServiceImpl.java    From mall4j with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public String uploadFile(byte[] bytes,String originalName) throws QiniuException {
	String extName = FileUtil.extName(originalName);
	String fileName =DateUtil.format(new Date(), NORM_MONTH_PATTERN)+ IdUtil.simpleUUID() + "." + extName;


	AttachFile attachFile = new AttachFile();
	attachFile.setFilePath(fileName);
	attachFile.setFileSize(bytes.length);
	attachFile.setFileType(extName);
	attachFile.setUploadTime(new Date());
	attachFileMapper.insert(attachFile);

	String upToken = auth.uploadToken(qiniu.getBucket(),fileName);
    Response response = uploadManager.put(bytes, fileName, upToken);
    Json.parseObject(response.bodyString(),  DefaultPutRet.class);
	return fileName;
}
 
Example 5
Source File: BackupController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 备份文章,导出markdown文件
 *
 * @return JsonResult
 */
public JsonResult backupPosts() {
    List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
    posts.addAll(postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc()));
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
        }
        //打包好的文件名
        String distName = "posts_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/posts/" + distName;
        for (Post post : posts) {
            HaloUtils.postToFile(post.getPostContentMd(), srcPath, post.getPostTitle() + ".md");
        }
        //打包导出好的文章
        ZipUtil.zip(srcPath, srcPath + ".zip");
        FileUtil.del(srcPath);
        log.info("Current time: {}, performed an article backup.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup article failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 6
Source File: BackupController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 备份资源文件 重要
 *
 * @return JsonResult
 */
public JsonResult backupResources() {
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/resources/");
        }
        File path = new File(ResourceUtils.getURL("classpath:").getPath());
        String srcPath = path.getAbsolutePath();
        String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        //执行打包
        ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
        log.info("Current time: {}, the resource file backup was performed.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup resource file failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 7
Source File: DeployServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, Long id) {
	String deployDate = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
	StringBuilder sb = new StringBuilder();
	backupPath += appName + FILE_SEPARATOR + deployDate + "\n";
	sb.append("mkdir -p ").append(backupPath);
	sb.append("mv -f ").append(fileSavePath);
	sb.append(appName).append(" ").append(backupPath);
	log.info("备份应用脚本:" + sb.toString());
	executeShellUtil.execute(sb.toString());
	//还原信息入库
	DeployHistory deployHistory = new DeployHistory();
	deployHistory.setAppName(appName);
	deployHistory.setDeployUser(SecurityUtils.getCurrentUsername());
	deployHistory.setIp(ip);
	deployHistory.setDeployId(id);
	deployHistoryService.create(deployHistory);
}
 
Example 8
Source File: BackupController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 备份数据库
 *
 * @return 重定向到/admin/backup
 */
public JsonResult backupDatabase() {
    try {
        if (HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
            FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
        }
        String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
        String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
        //压缩文件
        ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
        log.info("Current time: {}, database backup was performed.", DateUtil.now());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
    } catch (Exception e) {
        log.error("Backup database failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
    }
}
 
Example 9
Source File: UseHutool.java    From java-tutorial with MIT License 6 votes vote down vote up
/**
 * hutool 时间格式化
 */
public static void dateFormat() {

    String dateStr = "2017-03-01";
    Date date = DateUtil.parse(dateStr);
    //结果 2017/03/01
    String format = DateUtil.format(date, "yyyy/MM/dd");
    //常用格式的格式化,结果:2017-03-01
    String formatDate = DateUtil.formatDate(date);
    //结果:2017-03-01 00:00:00
    String formatDateTime = DateUtil.formatDateTime(date);
    //结果:00:00:00
    String formatTime = DateUtil.formatTime(date);
    System.out.println(format);
    System.out.println(formatDate);
    System.out.println(formatDateTime);
    System.out.println(formatTime);
}
 
Example 10
Source File: BaseApiClient.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
void createNewFileName(String key, String pathPrefix) {
    this.suffix = FileUtil.getSuffix(key);
    if (!FileUtil.isPicture(this.suffix)) {
        throw new GlobalFileException("[" + this.storageType + "] 非法的图片文件[" + key + "]!目前只支持以下图片格式:[jpg, jpeg, png, gif, bmp]");
    }
    String fileName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
    this.newFileName = pathPrefix + (fileName + this.suffix);
}
 
Example 11
Source File: TimeLineController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
@GetMapping("list")
public String timeline(HttpServletRequest request, HttpServletResponse response) {
    FqUserCache user = webUtil.currentUser(request, response);
    if(user == null){
        return USER_LOGIN_REDIRECT_URL;
    }
    UserTimeLineExample example = new UserTimeLineExample();
    example.setOrderByClause("create_time desc");
    example.createCriteria().andUserIdEqualTo(user.getId()).andCreateTimeGreaterThan(DateUtil.beginOfYear(new Date()));
    List<UserTimeLine> lines = timeLineService.selectByExample(example);
    Map<String, List<UserTimeLine>> map = Maps.newTreeMap(new Comparator<String>() {
        public int compare(String obj1, String obj2) {
            // 降序排序
            return obj2.compareTo(obj1);
        }
    });
    for (UserTimeLine line : lines) {
        String yearMonth = DateUtil.format(line.getCreateTime(), "yyyy-MM");
        if (map.get(yearMonth) == null) {
            List<UserTimeLine> linesNew = new ArrayList<UserTimeLine>();
            linesNew.add(line);
            map.put(yearMonth, linesNew);
        } else {
            map.get(yearMonth).add(line);
        }
    }
    request.setAttribute("map", map);
    return "/user/timeline.html";
}
 
Example 12
Source File: HutoolController.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
@ApiOperation("DateUtil使用:日期时间工具")
@GetMapping(value = "/dateUtil")
public CommonResult dateUtil() {
    //Date、long、Calendar之间的相互转换
    //当前时间
    Date date = DateUtil.date();
    //Calendar转Date
    date = DateUtil.date(Calendar.getInstance());
    //时间戳转Date
    date = DateUtil.date(System.currentTimeMillis());
    //自动识别格式转换
    String dateStr = "2017-03-01";
    date = DateUtil.parse(dateStr);
    //自定义格式化转换
    date = DateUtil.parse(dateStr, "yyyy-MM-dd");
    //格式化输出日期
    String format = DateUtil.format(date, "yyyy-MM-dd");
    //获得年的部分
    int year = DateUtil.year(date);
    //获得月份,从0开始计数
    int month = DateUtil.month(date);
    //获取某天的开始、结束时间
    Date beginOfDay = DateUtil.beginOfDay(date);
    Date endOfDay = DateUtil.endOfDay(date);
    //计算偏移后的日期时间
    Date newDate = DateUtil.offset(date, DateField.DAY_OF_MONTH, 2);
    //计算日期时间之间的偏移量
    long betweenDay = DateUtil.between(date, newDate, DateUnit.DAY);
    return CommonResult.success(null, "操作成功");
}
 
Example 13
Source File: LogController.java    From zfile with MIT License 5 votes vote down vote up
/**
 * 系统日志下载
 */
@GetMapping("/log")
public ResponseEntity<Object> downloadLog(HttpServletResponse response) {
    if (log.isDebugEnabled()) {
        log.debug("下载诊断日志");
    }
    String userHome = System.getProperty("user.home");
    File fileZip = ZipUtil.zip(userHome + "/.zfile/logs");
    String currentDate = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
    return FileUtil.export(fileZip, "ZFile 诊断日志 - " + currentDate + ".zip");
}
 
Example 14
Source File: UpLoadController.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * 单个文件上传
 *
 * @param file 前台传过来文件路径
 * @param dir  保存文件的相对路径,相对路径必须upload开头,例如upload/test
 * @return
 * @throws Exception
 */
public Map<String, String> upload(MultipartFile file, String dir) {
    Map<String, String> params = new HashedMap();
    String resultPath = "";
    try {
        String savePath = "";
        if (StringUtils.isNotBlank(dir)) {
            savePath = fileUploadPrefix + File.separator + "upload" + File.separator
                    + dir + File.separator + DateUtil.format(new Date(), "yyyyMMdd") + File.separator;
        } else {
            savePath = fileUploadPrefix + File.separator + "upload" + File.separator
                    + DateUtil.format(new Date(), "yyyyMMdd") + File.separator;
        }
        // 保存文件
        String realFileName = file.getOriginalFilename();
        Long fileName = System.currentTimeMillis();
        File targetFile = new File(new File(savePath).getAbsolutePath() + File.separator + fileName + realFileName.substring(realFileName.indexOf(".")));
        if (!targetFile.getParentFile().exists()) {
            targetFile.getParentFile().mkdirs();
        }
        FileUtils.copyInputStreamToFile(file.getInputStream(), targetFile);// 复制临时文件到指定目录下
        if (StringUtils.isNotBlank(resourceAccessUrl)) {
            resultPath = resourceAccessUrl + "/upload/" + dir + "/"
                    + DateUtil.format(new Date(), "yyyyMMdd") + "/"
                    + fileName + realFileName.substring(realFileName.indexOf("."));
        } else {
            resultPath = "/upload/" + dir + "/"
                    + DateUtil.format(new Date(), "yyyyMMdd") + "/"
                    + fileName + realFileName.substring(realFileName.indexOf("."));
        }

        params.put("fileName", realFileName);
        params.put("filePath", resultPath);

    } catch (Exception e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }
    return params;
}
 
Example 15
Source File: JacksonDateSerializer.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
    String string = null;
    if (date != null) {
        string = DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN);
    }
    jsonGenerator.writeString(string);
}
 
Example 16
Source File: AliyunOssService.java    From feiqu-opensource with Apache License 2.0 4 votes vote down vote up
/**
	 * 签名生成
	 * @return
	 */
	public JSONObject policy() {

		FileSystemClient fileSystemClient = FileSystemClient.getClient("aliyun");
		UploadTokenParam uploadTokenParam = new UploadTokenParam();
		// 存储目录
		String dir = DateUtil.format(new Date(),"yyyy/MM/dd");
		uploadTokenParam.setUploadDir(dir);
		// 签名有效期
		long expireEndTime = CommonConstant.ALIYUN_OSS_EXPIRE;
		uploadTokenParam.setExpires(expireEndTime);
		uploadTokenParam.setCallbackUrl(CommonConstant.ALIYUN_OSS_CALLBACK);
		uploadTokenParam.setFsizeMax(CommonConstant.ALIYUN_OSS_MAX_SIZE * 1024 * 1024);
		Map<String, Object> map =  fileSystemClient.createUploadToken(uploadTokenParam);
// 提交节点
		String action = "http://" + CommonConstant.ALIYUN_OSS_BUCKET_NAME + "." + CommonConstant.ALIYUN_OSS_ENDPOINT;
		map.put("action",action);
		map.put("myDomain", CommonConstant.ALIOSS_URL_PREFIX);
		JSONObject result = new JSONObject(map);
		return result;

		/*Date expiration = new Date(expireEndTime);
		// 文件大小
		long maxSize = CommonConstant.ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
		// 回调
		JSONObject callback = new JSONObject();
		callback.put("callbackUrl", CommonConstant.ALIYUN_OSS_CALLBACK);
		callback.put("callbackBody", "filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
		callback.put("callbackBodyType", "application/x-www-form-urlencoded");
		// 提交节点
		String action = "http://" + CommonConstant.ALIYUN_OSS_BUCKET_NAME + "." + CommonConstant.ALIYUN_OSS_ENDPOINT;
		try {
			PolicyConditions policyConds = new PolicyConditions();
			policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, maxSize);
			policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
			String postPolicy = aliyunOssClient.generatePostPolicy(expiration, policyConds);
			byte[] binaryData = postPolicy.getBytes("utf-8");
			String policy = BinaryUtil.toBase64String(binaryData);
			String signature = aliyunOssClient.calculatePostSignature(postPolicy);
			String callbackData = BinaryUtil.toBase64String(callback.toString().getBytes("utf-8"));
			// 返回结果
			result.put("OSSAccessKeyId", aliyunOssClient.getCredentialsProvider().getCredentials().getAccessKeyId());
			result.put("policy", policy);
			result.put("signature", signature);
			result.put("dir", dir);
			result.put("callback", callbackData);
			result.put("myDomain", CommonConstant.ALIOSS_URL_PREFIX);
			result.put("action", action);
		} catch (Exception e) {
			LOGGER.error("签名生成失败", e);
		}
		return result;*/
	}
 
Example 17
Source File: DeployServiceImpl.java    From eladmin with Apache License 2.0 4 votes vote down vote up
@Override
public String serverReduction(DeployHistory resources) {
	Long deployId = resources.getDeployId();
	Deploy deployInfo = deployRepository.findById(deployId).orElseGet(Deploy::new);
	String deployDate = DateUtil.format(resources.getDeployDate(), DatePattern.PURE_DATETIME_PATTERN);
	App app = deployInfo.getApp();
	if (app == null) {
		sendMsg("应用信息不存在:" + resources.getAppName(), MsgType.ERROR);
		throw new BadRequestException("应用信息不存在:" + resources.getAppName());
	}
	String backupPath = app.getBackupPath()+FILE_SEPARATOR;
	backupPath += resources.getAppName() + FILE_SEPARATOR + deployDate;
	//这个是服务器部署路径
	String deployPath = app.getDeployPath();
	String ip = resources.getIp();
	ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
	String msg;

	msg = String.format("登陆到服务器:%s", ip);
	log.info(msg);
	sendMsg(msg, MsgType.INFO);
	sendMsg("停止原来应用", MsgType.INFO);
	//停止应用
	stopApp(app.getPort(), executeShellUtil);
	//删除原来应用
	sendMsg("删除应用", MsgType.INFO);
	executeShellUtil.execute("rm -rf " + deployPath + FILE_SEPARATOR + resources.getAppName());
	//还原应用
	sendMsg("还原应用", MsgType.INFO);
	executeShellUtil.execute("cp -r " + backupPath + "/. " + deployPath);
	sendMsg("启动应用", MsgType.INFO);
	executeShellUtil.execute(app.getStartScript());
	sendMsg("应用启动中,请耐心等待启动结果,或者稍后手动查看启动状态", MsgType.INFO);
	int i  = 0;
	boolean result = false;
	// 由于启动应用需要时间,所以需要循环获取状态,如果超过30次,则认为是启动失败
	while (i++ < count){
		result = checkIsRunningStatus(app.getPort(), executeShellUtil);
		if(result){
			break;
		}
		// 休眠6秒
		sleep(6);
	}
	StringBuilder sb = new StringBuilder();
	sb.append("服务器:").append(ip).append("<br>应用:").append(resources.getAppName());
	sendResultMsg(result, sb);
	executeShellUtil.close();
	return "";
}
 
Example 18
Source File: CSVUtil.java    From scaffold-cloud with MIT License 4 votes vote down vote up
/**
 * 将查出来的列表按照指定的字段 转换为导出需要的数据集合格式
 * @param fieldNames 指定需要导出的列的字段名
 * @param BeanList 从数据库中查出的实体列表
 * @param convertorMap 字段转义map
 * @return 按照字段名生成的数据集合
 */
public static List<List<Object>> changeBeanlistToDatalist(String[] fieldNames, List<Object> BeanList, Map convertorMap) throws Exception {
    List<List<Object>> dataList = new ArrayList<>();
    for (int i = 0; i < BeanList.size(); i++) {
        Object bean = BeanList.get(i);
        Map<String ,Object> beanMap = PropertyUtils.describe(bean);
        List<Object> bean2data = new ArrayList<>(fieldNames.length);
        for (int j = 0; j < fieldNames.length; j++) {
            // fileName是字段名字
            String fieldName = fieldNames[j];
            // 这个拿出来的是该字段的值
            Object data = beanMap.get(fieldName);
            boolean isDate = false;
            if(data instanceof Date){
                isDate = true;
                // 将时间类型的转换成 yyyy-MM-dd HH:mm:ss格式的文本
                data = DateUtil.format((Date) data, "yyyy-MM-dd HH:mm:ss");
            }
            if(null != convertorMap && null != data){
                Map nidMap = (Map)convertorMap.get(fieldName);
                if(null != nidMap){
                    // 这里 data如果需要转义 需要用convertorMap进行处理
                    data = nidMap.get(data.toString());
                }
            }
            if(null != data && !"".equals(data)){
                // 如果data值是数字组成 并且长度大于12 加上table制表符 避免流水号订单号等被转成数值显示不完全
                final boolean flag =
                        !isDate && (!NumberUtil.isNumber(data.toString()) || data.toString().length() > 12);
                if(flag){
                    data = data.toString() + "\t";
                }
                // csv格式避免单元格中有英文逗号,用双引号引起来,避免存在双引号,则将原先的双引号转成两个双引号
                data = "\"" + data.toString().replaceAll("\"","\"\"") + "\"";
            }
            bean2data.add(null == data ? "" : data);
        }
        dataList.add(bean2data);
    }
    return dataList;
}
 
Example 19
Source File: OrderUtil.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 时间戳订单号
 * @return
 */
public static String orderSn(){
    Date date = DateUtil.date();
    return DateUtil.format(date,"yyyyMMddHHmmssSSS");
}
 
Example 20
Source File: OrderUtil.java    From yshopmall with Apache License 2.0 2 votes vote down vote up
/**
 * 时间戳订单号
 *
 * @return
 */
public static String orderSn() {
    Date date = DateUtil.date();
    return DateUtil.format(date, "yyyyMMddHHmmssSSS");
}