Advertisement

Java日期操作工具类DateUtils

  •  5星
  •     浏览量: 0
  •     大小:None
  •      文件类型:None


简介:
简介:DateUtils是一个便捷的Java工具类,提供了丰富的日期处理方法,包括格式化、解析、增减以及比较日期等实用功能。 在Java中常用的时间操作包括日期处理、时间戳转换、日历管理以及字符串之间的相互转化等功能。此外还涉及到计算两个时间点之间的时间差等常见需求。

全部评论 (0)

还没有任何评论哟~
客服
客服
  • JavaDateUtils
    优质
    简介:DateUtils是一个便捷的Java工具类,提供了丰富的日期处理方法,包括格式化、解析、增减以及比较日期等实用功能。 在Java中常用的时间操作包括日期处理、时间戳转换、日历管理以及字符串之间的相互转化等功能。此外还涉及到计算两个时间点之间的时间差等常见需求。
  • Java 对比
    优质
    简介:这是一个用于比较Java中日期对象差异的实用工具类,提供多种方法来计算两个日期之间的天数、月份和年份差值,简化了复杂的日期时间操作。 Java 日期比较工具类提供了各种日期操作及计算功能,包括获取两个日期之间的间隔天数、间隔月数以及格式化日期等功能。
  • Java(含获取指定转换和计算间隔天数功能)
    优质
    本工具类提供了一系列便捷方法用于处理Java中的日期操作,包括获取特定日期、格式化及解析日期字符串以及计算两个日期之间的差值等功能。 本段落主要介绍了Java日期操作工具类的详细用法,包括获取指定日期、进行日期转换以及计算相隔天数等功能。对这些内容感兴趣的读者可以参考此文。
  • Java时间大全
    优质
    本资源集合了多种Java日期与时间处理的工具类,涵盖格式化、解析、计算等实用功能,旨在帮助开发者高效解决项目中关于日期操作的各种需求。 Java日期时间工具类非常全面。该工具类包括以下功能:获得当前日期(格式为yyyy-MM-dd HH:mm:ss);获取系统当前时间戳;获取当前日期(格式为yy-MM-dd);得到两个时间差(格式为yyyy-MM-dd HH:mm:ss);转化long值的日期为yyyy-MM-dd HH:mm:ss.SSS格式的日期;判断当前日期是一个星期中的第几天;判断当前时间是否在[startTime, endTime]区间内;获取当前小时,例如2019-08-23 17;获取当前时间一个小时前的时间;获取前一天的日期;获得最近七天的数据范围;得到过去一个月内的日期范围;获取最近三个月的日期范围;返回当前年度季度等。
  • Java时间格式化
    优质
    简介:本工具类提供了一系列便捷的方法来处理和格式化Java中的日期与时间数据,适用于各种需要精准控制日期时间显示的应用场景。 最近整理了一个Java时间日期格式化的工具类,包含了目前常用的各种日期格式化方法。
  • Java文件——FileUtil
    优质
    简介:FileUtil是专为Java开发者设计的一款高效实用的文件操作工具类库,提供了一系列便捷的方法来处理常见的文件系统任务。 package com.hexiang.utils; import java.io.*; /** * FileUtil. Simple file operation class. * */ public class FileUtil { /** * The buffer. */ protected static byte buf[] = new byte[1024]; /** * Read content from local file. * * @param fileName - local file name to read * @return * @throws Exception */ public static String readFileAsString(String fileName) throws Exception { String content = new String(readFileBinary(fileName)); return content; } /** * 读取文件并返回为给定字符集的字符串. * * @param fileName * @param encoding * @return * @throws Exception */ public static String readFileAsString(String fileName, String encoding) throws Exception { String content = new String(readFileBinary(fileName), encoding); return content; } /** * 读取文件并返回为给定字符集的字符串. * * @param in * @return * @throws Exception */ public static String readFileAsString(InputStream in) throws Exception { String content = new String(readFileBinary(in)); return content; } /** * Read content from local file to binary byte array. * * @param fileName - local file name to read * @return * @throws Exception */ public static byte[] readFileBinary(String fileName) throws Exception { FileInputStream fin = new FileInputStream(fileName); return readFileBinary(fin); } /** * 从输入流读取数据为二进制字节数组. * * @param streamIn * @return * @throws IOException */ public static byte[] readFileBinary(InputStream streamIn) throws IOException { BufferedInputStream in = new BufferedInputStream(streamIn); ByteArrayOutputStream out = new ByteArrayOutputStream(10240); int len; while ((len = in.read(buf)) >= 0) out.write(buf, 0, len); in.close(); return out.toByteArray(); } /** * Write string content to local file. * * @param fileName - local file name will write to * @param content String text * @return true if success * @throws IOException */ public static boolean writeFileString(String fileName, String content) throws IOException { FileWriter fout = new FileWriter(fileName); fout.write(content); fout.close(); return true; } /** * Write string content to local file using given character encoding. * * @param fileName - local file name will write to * @param content String text * @param encoding the encoding * @return true if success * @throws IOException */ public static boolean writeFileString(String fileName, String content, String encoding) throws IOException { OutputStreamWriter fout = new OutputStreamWriter(new FileOutputStream(fileName), encoding); fout.write(content); fout.close(); return true; } /** * Write binary byte array to local file. * * @param fileName - local file name will write to * @param content binary byte array * @return true if success * @throws IOException */ public static boolean writeFileBinary(String fileName, byte[] content) throws IOException { FileOutputStream fout = new FileOutputStream(fileName); fout.write(content); fout.close(); return true; } /** * 检查文件名是否合法. 文件名字不能包含字符\/:*?<>| * * @param fileName 文件名,不包含路径 * @return boolean is valid file name */ public static boolean isValidFileName(String fileName) { boolean isValid = true; String errChar = \\/:*?\<>|; // if (fileName == null || fileName.length() == 0) { isValid = false; } else { for (int i = 0; i < errChar.length(); i++) { if (fileName.indexOf(errChar.charAt(i)) != -1) { isValid = false; break; } } } return isValid; } /** * 把非法文件名转换为合法文件名. * * @param fileName * @return */ public static String replaceInvalidFileChars(String fileName) { StringBuffer out = new StringBuffer(); for (int i = 0; i < fileName.length(); i++) { char ch = fileName.charAt(i); // Replace invlid chars: \\/:*?\<>| switch (ch) { case \\: case /: case :: case *: case ?: case \: case <: case >: out
  • Java计算两个间非的分钟差或秒数
    优质
    本工具类用于高效计算两个给定日期间的非工作日总时长,支持输出结果为分钟或秒的形式,适用于项目中对时间精确管理的需求。 此工具类在原有基础上进行优化,分为两种情况:精确到分钟(保留两位小数),以及需要自行加工以实现精确到秒的功能。 入口方法为 getWorkHours。
  • Java全面的时间,涵盖年月
    优质
    这是一个全面的Java时间处理工具类库,提供了丰富的接口和方法来方便地进行日期、月份、年份及星期的操作。 Java时间操作工具类已经封装完成,包含获取某一时间的年、月、日和星期的功能。此外还支持对特定时间进行年份、月份、日期及周数的加减运算,并能提供某一时点所在年的年初到该时点的时间段、月度月初至该时刻的时间段以及具体日期当天0点到当前时刻的时间片段等信息,同时也能获得一周内从周一零点起始直至指定时间为止的具体时间段。
  • Java字符串和型的转换
    优质
    本工具类提供了丰富的Java方法,用于实现字符串与日期类型之间的便捷转换,旨在简化开发人员在项目中的数据处理工作。 本段落详细介绍了Java字符串与日期类型转换的工具类,并具有一定的参考价值。有兴趣的朋友可以查阅一下。
  • Java实现的SFTP
    优质
    这是一个用Java编写的SFTP操作工具类,提供了文件上传、下载、删除等基本功能,方便开发者在项目中集成SFTP服务。 1分即可获得SFTP常用操作工具。该工具支持以下功能: 1) 获取当前工作目录地址; 2) 改变到配置的远程目录; 3) 取得文件夹列表; 4) 列出文件; 5) 下载文件; 6) 复制文件; 7) 删除文件; 8) 检查指定路径是否为目录或存在特定文件; 9) 移动文件。 10)可以基于chnSftp对象进行开发,所需依赖类包在我的sftp包中提供。 版权声明:本工具类是个人兴趣驱动下使用chnSftp编写的应用。该软件归我个人所有,在办公环境中推广及互联网环境下欢迎使用和反馈。如果在任何环境内认为此应用程序不适宜,请删除我的工具软件。