博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
时间戳和字符串之间的互相转换
阅读量:7265 次
发布时间:2019-06-29

本文共 1019 字,大约阅读时间需要 3 分钟。

import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class TestTime {public static void main(String[] args) {String time = "2010年12月08日11时17分00秒";System.out.println(time);// 字符串=======>时间戳String re_str = getTime(time);System.out.println(re_str);// 时间戳======>字符串String data = getStrTime(re_str);System.out.println(data);}// 将字符串转为时间戳public static String getTime(String user_time) {String re_time = null;SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");Date d;try {d = sdf.parse(user_time);long l = d.getTime();String str = String.valueOf(l);re_time = str.substring(0, 10);} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}return re_time;}// 将时间戳转为字符串public static String getStrTime(String cc_time) {String re_StrTime = null;SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");// 例如:cc_time=1291778220long lcc_time = Long.valueOf(cc_time);re_StrTime = sdf.format(new Date(lcc_time * 1000L));return re_StrTime;}}

 

转载地址:http://jvgdm.baihongyu.com/

你可能感兴趣的文章
数据保护与管理的春天来了
查看>>
企业“移动办公”和“无桌办公”走向前沿
查看>>
Edge浏览器曝新漏洞:可被攻击者窃取cookie与密码数据
查看>>
SonarPython 1.8 发布,Sonar 的 Python 检查扩展
查看>>
yum安装openssl-devel报错
查看>>
《MATLAB信号处理超级学习手册》——1.2 MATLAB基本操作
查看>>
【每日一博】编程警句
查看>>
《数据科学R语言实践:面向计算推理与问题求解的案例研究法》一一1.2 原始数据...
查看>>
盘点 7 款应用最广泛的 Linux 桌面环境
查看>>
Windows 10 S 系统确认不允许挂载 Linux 分支
查看>>
甲骨文企业云用户可选择 Ubuntu
查看>>
远程攻击 Android 蓝牙
查看>>
《产品设计与开发(原书第5版)》——3.5 步骤2:挖掘并探索大量机会方案...
查看>>
《淘宝网开店 进货 运营 管理 客服 实战200招》——2.4 怎样在批发市场进到 更便宜的货...
查看>>
《C语言解惑》—— 3.2 数据类型的后缀符号
查看>>
Flash 再遭重创:Twitch 或明年完成 HTML5 转换
查看>>
《Power Designer系统分析与建模实战》——第3章 业务处理模型BPM
查看>>
《编译与反编译技术实战 》一3.4 本章小结
查看>>
【持续更新】上海云栖大会,阿里云都重磅发布了啥?重要消息一文荟萃!
查看>>
《设计模式解析(第2版•修订版)》—第1章 1.1节概览
查看>>