时间戳、String、Date转换
时间戳(String or long) =》Date
long s=1557230621043L;
Date date=new Date(s);
System.out.println(date);
Date转时间戳
getTime()
string.date相互转换
//string转date
public static void stringToDate(){
try{
String str="2016-10-24 21:59:06";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.parse(str));
System.out.println(sdf.parse(str).getTime());
}catch(Exception e){
e.printStackTrace();
}
} //date转string1
public static void dateToString1(){
try {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
System.out.println(format.format(new Date().getTime()));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
} //date转string2
public static void dateToString2(){
try{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
Calendar cal=Calendar.getInstance();
System.out.println(format.format(cal.getTime()));
}catch(Exception e){
e.printStackTrace();
}
}
系统微秒
System.currentTimeMillis();
纳秒
System.nanoTime();
时间戳、String、Date转换的更多相关文章
- java 时间戳与date转换
1.时间戳转换为date long sjc=1442633777; SimpleDateFormat t = new SimpleDateFormat("yyyyMMddHHmmss&quo ...
- oracle unix时间戳与date转换
linux 时间戳 转date: 创建自定义函数: create or replace function unix_to_oracle(in_number number) return date ...
- Calendar /String /Date 转换
Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDate ...
- 使用date转换UNIX时间戳
1.将time string转换成时间戳 date -d "2010-10-12 12:25:00" +%s 2.将时间戳转换成time string date -d " ...
- Java日期与时间的处理/Date,String,Calendar转换
public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=Syst ...
- 【Java】【9】String Date Calendar之间的转换
前言: 1, Calendar 转化 String 2, Calendar 转化 Date 3,Date 转化 String 4,Date 转化 Calendar 5,String 转化 Calend ...
- [java]转:String Date Calendar之间的转换
String Date Calendar之间的转换 String Date Calendar 1.Calendar 转化 String Calendar calendat = Calendar.ge ...
- java String和Date转换
SimpleDateFormat函数语法: G 年代标志符 y 年 M 月 d 日 h 时 在上午或下午 (1~12) H 时 在一天中 (0~23) m 分 s 秒 S 毫秒 ...
- String与Date转换
public class TimeTraining { public static void changeStr(String str){ str = "137878"; } pu ...
随机推荐
- vmware安装win7*64位时,安装不成功的关键点是光驱接口类型选择为IDE模式
mware 安装win7*64时,找不到光盘,后来在xin7*64的虚拟机下的编辑虚拟机设置 找到光驱,点击高级,并选择IDE即可,这样就可以进入虚拟机找到光驱和硬盘到了.进入winpe后可以看到各种 ...
- Windows下命令行Git无法显示中文问题解决方案
Windows下Git设置编码正常显示中文: 在 CMD 下设置环境变量 set LESSCHARSET=utf-8 在 PowerShell 下设置环境变量 $env:LESSCHARSET='ut ...
- WUSTOJ 1279: Wallace and His Pet(Java)
1279: Wallace and His Pet 题目 给出一句话(英文),单词总数不超过1000,每个单词不超过10个字符,一句话只有一个唯一的字符"."(句点).将这句话 ...
- 【BFS】Help the Princess!
题目描述 The people of a certain kingdom make a revolution against the bad government of the princess. T ...
- AtCoder Grand Contest 040 A - ><
传送门 对于某个位置,只要知道这个位置往左最多的连续 $\text{<}$ 的数量 $x$ 和往右最多的连续 $\text{>}$ 的数量 $y$ 那么这个位置最小可能的数即为 $max( ...
- python练习:函数4
''' 1.定义一个func(name),该函数效果如下. assert func("lilei") = "Lilei" assert func("h ...
- c#学习笔记-深度复制 与浅度复制
关于值类型和引用类型: 浅度复制(shallow copy)只复制值类型(char,int )的值,而对于引用类型不会复制,浅度复制可以通过派生于System.Object的MemberwiseClo ...
- Mysql 更新时间
Mysql时间加减函数为date_add().date_sub() 定义和用法DATE_ADD() 函数向日期添加指定的时间间隔.DATE_SUB() 函数向日期减少指定的时间间隔.语法DATE_AD ...
- leetcode-62. Unique Paths · DP + vector
题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- Linq以本周和本月为条件的Sql,Liqn查询本周,Linq查询本月
//计算本周时间 时间 > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.DayOfWeek) //计算本月时间 时间 > ...