我想在JavaScript中解析没有时区的日期.我试过了:
new Date(Date.parse("2005-07-08T00:00:00+0000"));
Run Code Online (Sandbox Code Playgroud)
返回Fri Jul 08 2005 02:00:00 GMT + 0200(欧洲中部夏令时)
new Date(Date.parse("2005-07-08 00:00:00 GMT+0000"));
Run Code Online (Sandbox Code Playgroud)
返回相同的结果
new Date(Date.parse("2005-07-08 00:00:00 GMT-0000"));
Run Code Online (Sandbox Code Playgroud)
返回相同的结果
我想解析一下时间:
没有时区.
不调用构造函数Date.UTC或新日期(年,月,日).
只需简单地将字符串传递给Date构造函数(没有原型方法).
我必须要产品Date对象,而不是String.
为了显示可重现的场景,我正在做以下事情
获取当前系统时间(当地时间)
将本地时间转换为UTC //在这里工作正常
反转UTC时间,返回当地时间.遵循3种不同的方法(如下所列),但所有3种方法仅保留UTC时间.
{
long ts = System.currentTimeMillis();
Date localTime = new Date(ts);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat (format);
// Convert Local Time to UTC (Works Fine)
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmtTime = new Date(sdf.format(localTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());
// Reverse Convert UTC Time to Locale time (Doesn't work) Approach 1
sdf.setTimeZone(TimeZone.getDefault());
localTime = new Date(sdf.format(gmtTime));
System.out.println("Local:" + localTime.toString() + "," …Run Code Online (Sandbox Code Playgroud)java utc simpledateformat date-formatting timestamp-with-timezone
我正在尝试使用预准备语句将包含日期,时间和时区的字符串插入到我的数据库的时区字段的时间戳中.
问题是Timestamp.valueof函数没有考虑字符串包含的时区,因此它会导致错误.接受的格式是yyyy- [m] m- [d] d hh:mm:ss [.f ...],没有提到时区.
这是导致错误的确切代码:
pst.setTimestamp(2,Timestamp.valueOf("2012-08-24 14:00:00 +02:00"))
有什么方法可以克服它吗?提前致谢!
postgresql timestamp prepared-statement value-of timestamp-with-timezone
我收到我的数据:UTC中的日期和时间,在单独的列中以csv文件格式.因为我需要将这个区域转换为我住的地方的日期和时间,目前在夏天到UTC + 2,也许还有其他一些区域我想知道在我们谈论的时候在postgres中插入数据的最佳做法是什么数据类型.我应该将我的两个数据放在一个列中,还是将它们分开作为类型:日期和时间,如果不是,我应该使用时间戳或时间戳(或其他).
我有以下Java.lang.String代表String值的值TIMESTAMPTZ.我需要转换这些Java.lang.String TO oracle.sql.TIMESTAMPTZ.
"2016-04-19 17:34:43.781 Asia/Calcutta",
"2016-04-30 20:05:02.002 8:00",
"2003-11-11 00:22:15.0 -7:00",
"2003-01-01 02:00:00.0 -7:00",
"2007-06-08 15:01:12.288 Asia/Bahrain",
"2016-03-08 17:17:35.301 Asia/Calcutta",
"1994-11-24 11:57:17.303"
Run Code Online (Sandbox Code Playgroud)
我试过很多方面.
样本1:
通过使用尝试 SimpleDateFormat
String[] timeZoneValues = new String[]{"2016-04-19 17:34:43.781 Asia/Calcutta", "2016-04-30 20:05:02.002 8:00", "2003-11-11 00:22:15.0 -7:00", "2003-01-01 02:00:00.0 -7:00", "2007-06-08 15:01:12.288 Asia/Bahrain", "2016-03-08 17:17:35.301 Asia/Calcutta", "1994-11-24 11:57:17.303"};
for(String timeZoneValue: timeZoneValues){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS XXX");
try {
simpleDateFormat.parse(timeZoneValue);
} catch (ParseException e) {
e.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) java timezone oracle11g simpledateformat timestamp-with-timezone
我在我的PHP中有这个代码
function nicetime($date)
{
date_default_timezone_set("Asia/Taipei");
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if(empty($unix_date)) {
return "Bad date";
}
// is it future date or past date
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for($j = 0; $difference >= …Run Code Online (Sandbox Code Playgroud) 我需要在查询中将DATE值转换为TIMESTAMP WITH TIME ZONE,但是目前我得到的TimeZone Region('Europe/Paris')无法被EF使用.
例如,这样做时:
select CAST(FECHA AS TIMESTAMP WITH TIME ZONE) from test;
Run Code Online (Sandbox Code Playgroud)
我目前得到这个输出:
07/03/14 09:22:00,000000000 EUROPE/PARIS
Run Code Online (Sandbox Code Playgroud)
但我需要它像:
07/03/14 09:22:00,000000000 +01:00
Run Code Online (Sandbox Code Playgroud)
知道怎么做到这一点?
我为外汇DataFrame阅读了Pandas更改时区,但是我想让我的数据帧时区的时间列与sqlite3数据库的互操作性.
我的pandas数据帧中的数据已经转换为UTC数据,但我不想在数据库中维护此UTC时区信息.
给出从其他来源获得的数据样本,它看起来像这样:
print(type(testdata))
print(testdata)
print(testdata.applymap(type))
Run Code Online (Sandbox Code Playgroud)
得到:
<class 'pandas.core.frame.DataFrame'>
time navd88_ft station_id new
0 2018-03-07 01:31:02+00:00 -0.030332 13 5
1 2018-03-07 01:21:02+00:00 -0.121653 13 5
2 2018-03-07 01:26:02+00:00 -0.072945 13 5
3 2018-03-07 01:16:02+00:00 -0.139917 13 5
4 2018-03-07 01:11:02+00:00 -0.152085 13 5
time navd88_ft station_id \
0 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
1 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
2 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
3 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
4 …Run Code Online (Sandbox Code Playgroud) 在我的客户端应用程序中,我根据其IP获取来自skyhook API的纬度和经度信息
现在根据纬度和经度信息,我需要找出客户端的时区信息.但是在Google时区API文档https://developers.google.com/maps/documentation/timezone/中,我看到时间戳是必填字段.在哪种情况下我应该做什么.
还能帮助我理解时间戳对应的内容吗?例如: - 如果我的应用程序服务器位于美国(比如PST时区),它会使google API调用传递服务器时间戳.
如果用户从印度传入lat/long信息登录到客户端应用程序,则向应用服务器获取时区信息API将提供什么作为dstOffset和rawOffset?即如果我使用dstOffset和rawOffset添加服务器时间戳,我将获取客户端机器时区信息?
我有一个名为 JavaScript 函数updateLatestDate,它接收对象的参数数组。
数组中对象的属性之一是MeasureDate日期类型的属性。
该函数updateLatestDate返回数组中存在的最新日期。
这是函数:
function updateLatestDate(sensorsData) {
return new Date(Math.max.apply(null, sensorsData.map(function (e) {
return new Date(e.MeasureDate);
})));
}
Run Code Online (Sandbox Code Playgroud)
这是函数接收参数的示例:
[{
"Address": 54,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2009-11-27T18:10:00",
"MeasureValue": -1
},
{
"Address": 26,
"AlertType": 1,
"Area": "West",
"MeasureDate": "2010-15-27T15:15:00",
"MeasureValue": -1
},
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2012-10-27T18:10:00",
"MeasureValue": -1
}]
Run Code Online (Sandbox Code Playgroud)
该函数updateLatestDate将返回MeasureDate数组中最后一个对象的值。
它看起来像这样:
var latestDate = Sat Oct 27 2012 21:10:00 GMT+0300 (Jerusalem Daylight …Run Code Online (Sandbox Code Playgroud)