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. ScrollView & HorizontalScrollView

    可垂直或水平滚动的列表 ScrollView & HorizontalScrollView内部只能有一个直接的子元素, <?xml version="1.0" enc ...

  2. Angular记录(6)

    文档资料 箭头函数--MDN:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_fun ...

  3. System系统类

    System系统类 : 主要的作用是用于获取系统的一个参数. System类需要掌握的方法: arraycopy(Object src, int srcPos, Object dest, int de ...

  4. arcgis图层 GraphicsLayer与FeatureLayer

    什么是图层 图层是用来在 ArcGIS 产品套件中显示地理数据集的机制.每个图层代表一种数据集(可以是地图服务.图形或是矢量数据),并指定该数据集是如何描绘使用一组属性的. 包含一个地图控件的每个应用 ...

  5. 20155324《网络对抗》Exp06 信息搜集与漏洞扫描

    20155324<网络对抗>Exp06 信息搜集与漏洞扫描 实践内容 各种搜索技巧的应用 DNS IP注册信息的查询 基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点 ...

  6. Android防止手动添加的本地库文件被NDK工具清理掉

    比如要添加一个名为libocr的本地库,先将libocr.so文件拷贝到jni目录下,然后在Android.mk文件中添加以下语句即可. 例: LOCAL_PATH := $(call my-dir) ...

  7. vue生命周期的理解

    我从官网上下载了一张vue生命周期的图,接下来实际分析一波vue到底执行了什么东西. 1.我们在使用vue时必不可少的操作就是 var vm = new Vue({}),这样我们就创建了一个vue的实 ...

  8. sparkRDD相关操作

    RDD(弹性分布式数据集).RDD以分区中的每一行进行分布式计算.父子依赖关系. 一.RDD创建操作 1)数据集合 Val data=Array(1, 2, 3, 4, 5, 6, 7, 8, 9) ...

  9. linux --xampp 配置多个网站

    我们想要在本地安装两个测试域名,www.abc.tld, www.xyz.tld, 分别指向到 htdoc 目录下的 abc.tld 和 xyz.tld 文件夹下.tld 是顶级域名 the top ...

  10. 搭建企业git代码版本管理所需工具

    此片文章纯属记录一下使用gitlab搭建私有git版本管理的一些工具及概念. 先记录一下概念 git         是一种版本控制系统,是一个命令,是一种工具 github   是一个基于git实现 ...