10 友盟项目--日期工具类、时间对齐、地理类库Geolite
1.日期工具类

import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; /** * 日期工具类 */ public class DateUtil { private static final String PATTERN_US_DATE = "dd/MMM/yyyy:HH:mm:ss Z" ; /** * 默认使用的解析方式 */ public static long parseDateStr(String dateStr) throws ParseException { return parseDateStr(dateStr , "yyyy/MM/dd HH:mm:ss" , Locale.CHINA ) ; } /** * 默认使用的解析方式 */ public static long parseDateStrInUS(String dateStr) throws ParseException { return parseDateStr(dateStr , PATTERN_US_DATE , Locale.US ) ; } /** * 解析时间串,生成时间戳 */ public static long parseDateStr(String dateStr , String fmt , Locale locale) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(fmt , locale) ; return sdf.parse(dateStr).getTime() ; } /** * 使用默认的格式(yyyy/MM/dd HH:mm:ss)格式化时间对象 */ public static String formatDate(Date date){ return formatDate(date , "yyyy/MM/dd HH:mm:ss") ; } /** * 使用指定的格式格式时间对象 */ public static String formatDate(Date date , String fmt){ SimpleDateFormat sdf = new SimpleDateFormat(fmt) ; return sdf.format(date) ; } /** * 使用指定的格式格式时间戳对象 */ public static String formatDate(long timestamp , String fmt){ return formatDate(new Date(timestamp) ,fmt) ; } /** * 使用时间戳格式化默认的时间串 */ public static String formatDate(long timestamp){ return formatDate(new Date(timestamp)) ; } }
测试日期工具类
public class TestDateFormat { /** * Locale :地域信息 ,国际化 */ @Test public void test1() throws Exception { Date now = new Date() ; SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z" ,Locale.US) ; //System.out.println(df.format(now)) ; String str = "28/Oct/2018:20:43:46 -0700" ; Date thatDate = df.parse(str) ; //1540784626000 System.out.println(thatDate.getTime()); Date newDate = new Date(1540784626000L) ; System.out.println(df.format(newDate)); } @Test public void test2() throws Exception { String str = "28/Oct/2018:20:43:46 -0700" ; long ts = DateUtil.parseDateStrInUS(str) ; System.out.println(ts); String dateStr = DateUtil.formatDate(ts) ; System.out.println(dateStr); System.out.println(DateUtil.parseDateStr(dateStr)) ; } }
2.地理类库Geolite
分类:
大数据项目
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下