分别获取年 月 日 时 分 秒 毫秒
https://www.cnblogs.com/ZenoLiang/p/8478050.html
java工具类
- DateUtils:时间工具类
- StringUtils
- StrUtil
- Guava(Google 核心的 Java 常用库)
- apache commons
- CollectionUtils
- SignatureAlgorithm
java面向对象视频教程
https://www.bjsxt.com/down/8691.html
将 Exception 转化为 String
/**
* 将 Exception 转化为 String
* @param e 异常
* @return
*/
public static String getExceptionToString(Throwable e) {
if (e == null) {
return "";
}
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
参照slj4格式字符串
-方式1
/**
* 格式化通知信息,参照slj4格式
* @param format
* @param strs
*/
public static void notice(Notice notice, String format, Object... strs) {
String sub = "\\{\\}";
for (int i = 0; i < strs.length; i++) {
if (format.contains("{}")) {
// java.util.regex.Matcher.quoteReplacement解决值有如$特殊字符的Illegal group reference问题
format = format.replaceFirst(sub, java.util.regex.Matcher.quoteReplacement(strs[i].toString()));
}
}
notice.noticeHigh(format);
}
方式2:
String.format("%s %s %s %s %s 余币不足,刷单所需:%s 剩余:%s",
strategyName, id, e.getName(), e.getSymbol(), e.getAccess(),
amount, freeBase);
时间常量(毫秒)工具类
/**
* @author yuanfeng.z
* @description 时间常量(毫秒)工具类
* @date 2019/1/28 18:20
*/
public class TimeUtil {
public static long SECOND = 1000L;
public static long MINUTE = SECOND * 60L;
public static long HOUR = MINUTE * 60L;
public static long DAY = HOUR * 24L;
public static long WEEK = DAY * 7L;
public static long MONTH = DAY * 30L;
public static long YEAR = DAY * 365L;
}
随机生成11位数工具类
/**
* 生成11位的随机的订单id
* bug:生成的idStr长度不一定一样
* @return
*/
private String randomId() {
// 11位
final double size = 100000000000d;
Random random = new Random();
double id = Math.floor(random.nextDouble() * size);
DecimalFormat df = new DecimalFormat("#");
String idStr = df.format(id);
return idStr;
}
网友评论