将日期转换为时间戳UTC [英] convert date to timestamp UTC

查看:430
本文介绍了将日期转换为时间戳UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java新手,想知道如何将日期转换为时间戳,例如

I am new to Java and wanted to know how can I convert date to timestamp like

http://www.timestampconvert.com/?go1=true&m=08&d=06&y=2007&hours=05&min=30&sec=000&Submit=++++++Convert+to+timestamp+++++&offset=-5.5 if I pass a date to it and vice versa..

我在此处在StackOverflow上进行搜索,但没有一个问题能解决我的问题

I searched here on StackOverflow but none of the questions have solved my problem

我需要在JSON中使用此时间戳作为highcharts API上的参数来显示点数

I need to use this timestamp in my JSON as a parameter on the highcharts API to show points

http://www.highcharts .com/samples/data/jsonp.php?filename = msft-c.json& callback =

推荐答案

要将日期转换为时间戳记:

To convert a date to a timestamp:

String date = "2014-08-03 15:20:10"; //Replace with your value
Timestamp timestamp = Timestamp.valueOf(date);
// Convert timestamp to long for use
long timeParameter = timestamp.getTime();

要将时间戳转换为日期:

To convert a timestamp to a date:

long timeParameter = 1186358400; //Replace with your value
Timestamp timestamp = new Timestamp(timeParameter);
Date date = new Date(timestamp.getTime());
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String textDate = df.format(date); // This gives a string like "2014-08-03 15:20:10"

希望这会有所帮助!

这篇关于将日期转换为时间戳UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆