1、时间转时间戳

public static long strToTimestamp(String dateTimeStr) throws Exception {
Timestamp time = Timestamp.valueOf(dateTimeStr);
return time.getTime();
}

2、时间戳转时间

public static String timestampToStr(long timestamp) throws Exception {
Timestamp ts = new Timestamp(timestamp);
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(ts);
}

3、时间转换

    public static Map strTimeTomap(String dateTimeStr) throws Exception {
// Timestamp ts = new Timestamp(timestamp);
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); Date date = sdf.parse(dateTimeStr);
cal.setTime(date);
String week_day = String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1);
String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.DAY_OF_MONTH, 1);
String first_day_month = dsdf.format(cal.getTime());
// System.out.println(first_day_month); cal.setTime(date);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
String first_day_week = dsdf.format(cal.getTime());
// System.out.println(first_day_week); String day = dsdf.format(date);
Map map = new HashMap<String,String>();
map.put("hour",hour);
map.put("day",day);
map.put("week_day",week_day);
map.put("first_day_week",first_day_week);
map.put("first_day_month",first_day_month); return map;
} @Test
public void test() throws Exception {
System.out.println(strTimeTomap("2019-04-18 12:31:05"));
}

java时间处理,获取当前时间的小时,天,本周周几,本周周一的日期,本月一号的日期的更多相关文章

  1. Python获取当前时间_获取格式化时间_格式化日期

    Python获取当前时间_获取格式化时间: Python获取当前时间: 使用 time.time( ) 获取到距离1970年1月1日的秒数(浮点数),然后传递给 localtime 获取当前时间 #使 ...

  2. 【转】python 输入一个时间,获取这个时间的下一秒

    原文:https://blog.csdn.net/l_d_56/article/details/84832198 输入一个时间,获取这个时间的下一秒 PS:下面代码使用于 python 2.7 tim ...

  3. Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数

    格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...

  4. js 的date的format时间,获取当前时间,前一天的日期

    Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...

  5. golang 时间戳 时间格式化 获取当前时间 timestamp 计算时间差

    获取当前时间 func Now func Now() Time 1 Now returns the current local time. func (Time) UTC func (t Time) ...

  6. C# 获取两个时间段之间的所有时间与获取当前时间所在的季度开始和结束时间

    一:C# 获取两个时间段之间的所有时间 public List<string> GetTimeList(string rq1, string rq2) { List<string&g ...

  7. MySQL时间函数-获取当前时间-时间差

    MySQL中获取当前时间为now(),不同于sqlserver getdate(). SQLServer转MySQL除变化top 1 -> limit 1之后报错: limit [Err] 15 ...

  8. redis基本操作,基于StringRedisTemplate,存储,取值,设置超时时间,获取超时时间,插入list操作

    @Autowired private StringRedisTemplate stringRedisTemplate; @GetMapping("/test") void test ...

  9. java中如何获取系统时间

    需要引入的包有: import java.util.Date; 此为获取当前系统时间,合适为“1991-01-01” String now = "";    SimpleDateF ...

随机推荐

  1. python模拟蒙特·卡罗法计算圆周率

    蒙特·卡罗方法是一种通过概率来得到问题近似解的方法,在很多领域都有重要的应用,其中就包括圆周率近似值的计问题. 假设有一块边长为2的正方形木板,上面画一个单位圆,然后随意往木板上扔飞镖,落点坐标(x, ...

  2. 编写高质量的Python代码系列(七)之协作开发

    如果多个人要开发同一个Python程序,那就得仔细商量代码的写法了.即使你是一个人开发,也需要理解其他人所写的模块.本节讲解多人协作开发Python程序时所用的标准工具及最佳做法. 第四十九条:为每个 ...

  3. Springboot集成Thymeleaf

    Thymeleaf 官方解释: Thymeleaf是一个用于web和独立环境的现代服务器端Java模板引擎. Thymeleaf的主要目的是将优雅的自然模板引入到您的开发工作流中——以使HTML可以在 ...

  4. 快速掌握Nginx(二) —— Nginx的Location和Rewrite

    1 location详解 1.location匹配规则 Nginx中location的作用是根据Url来决定怎么处理用户请求(转发请求给其他服务器处理或者查找本地文件进行处理).location支持正 ...

  5. J.U.C-volatile

      禁止指令重排  

  6. windows查看已连接WIFI密码

    找到wifi图标. 右键,选择打开“网络和internet设置”,选择状态. 选择更改适配器设置. 选择你所连接的WIFI网络. 右键,选择状态. 选择无线属性. 选择安全. 勾选显示字符.

  7. Swift 4 关于Darwin这个Module

    大家在做app或者framework的时候经常会用到生成随机数的方法arc4random系列,或者取绝对值abs()等.所以我有一次好奇的想看看在Developer Document里 是怎么描述这些 ...

  8. JSP循环缓存列表

    两种方法: 例如,有下拉框 <select></select>其中选项需要循环显示 1.JAVA代码循环 <% for(int i=0;i<list.size(); ...

  9. spring.http.multipart.maxFileSize提示无效报错问题处理

    在SpringBoot项目中,配置spring.http.multipart.maxFileSize用于限定最大文件上传大小. 但是,SpringBoot版本不同,关于这一块的配置也不相同. 1.Sp ...

  10. L1-Day10

    1.你需要的是更多的练习.[我的翻译]That you need is more practice.[标准答案]What you need is more practice[对比分析]主语从句用Tha ...