java时间戳转换日期格式(java时间戳转换日期格式精确到毫秒)
java中如何实现时间戳和北京时间的互换
public static void main(String[] args) {
long times = 1386665666777L;
Date date = new Date(times);
try {
SimpleDateFormat ss = new SimpleDateFormat(“yyyy-MM-dd hhss”);
System.out.println(ss.format(date));
} catch (Exception e) {
e.printStackTrace();
}
}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 block
e.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=1291778220
long lcc_time = long.valueof(cc_time);
re_strtime = sdf.format(new date(lcc_time * 1000l));
return re_strtime;
打印结果为:
2010年12月08日11时17分00秒
1291778220
2010年12月08日11时17分00秒
只精确到秒
java如何将时间戳转换为时间字符串
public static String getStrTime(String cc_time) {
String re_StrTime = null;
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy年MM月dd日HH时mm分ss秒”);
// 例如:cc_time=1291778220
long lcc_time = Long.valueOf(cc_time);
re_StrTime = sdf.format(new Date(lcc_time * 1000L));
return re_StrTime;
还没有评论,来说两句吧...