jQuery 如何将“字符串”转换为“没有时区的时间戳”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18913236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert "string" to "timestamp without time zone"
提问by Aijaz Chauhan
I am new to Postgresql and I am using WCF services.
Here is my code snippet:
我是 Postgresql 的新手,我正在使用 WCF 服务。
这是我的代码片段:
$.ajax({
url: '../Services/AuctionEntryServices.svc/InsertAuctionDetails',
data: JSON.stringify({ "objAuctionEntryEntity": {
"AuctionNO": '',
"AuctionDate": $('[Id$="lblAuctionDateVal"]').text(),
"TraderID": $('[Id$="ddlTraderName"] option:selected').val(),
"Grade": $('[Id$="ddlGrade"] option:selected').val(),
"Varity": $('[Id$="ddlVarity"] option:selected').val(),
"QuntityInAuction": $('#txtQuantityForAuction').val(),
"AuctionRate": $('#txtAuctionRate').val(),
"BrokerID": a[0],
"IsSold": $('#chlIsSold').is(':checked'),
"CreatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
"UpdatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
"CreationDate": GetCurrentDate().toMSJSON(),
"IsActive": true,
"AuctionTransaction": arrAuctionTransaction,
"MandiID": $.parseJSON(GetCookie('Admin_User_In_Mandi')).MandiID,
"FarmerID": _ownerid,
"AuctionNO": _auctionno,
"AmmanatPattiID": _ammantpattiid,
"ToTraderID": b[0],
"ToTraderName": $('#txtOtherBuyerNameEN').val(),
"ToTraderName_HI": $('#txtOtherBuyerNameHI').val()
}
}),
type: 'POST',
contentType: 'application/json',
dataType: 'json'
});
Here:
这里:
$('[Id$="lblAuctionDateVal"]').text() = "20/8/2013 14:52:49"
And my data type for this field is timestamp without time zone
.
How to convert this string to timestamp without time zone
data type?
我的这个字段的数据类型是timestamp without time zone
.
如何将此字符串转换为timestamp without time zone
数据类型?
回答by Erwin Brandstetter
String representation of a timestamp
(= timestamp without time zone
) depends on your locale settings. Therefore, to avoid ambiguities leading to data erros or Postgres coughing up an exception, you have two options:
a timestamp
(= timestamp without time zone
) 的字符串表示取决于您的语言环境设置。因此,为了避免歧义导致数据错误或 Postgres 咳出异常,您有两种选择:
1.)Use ISO 8601 format, which works the same with anylocale or DateStyle
setting:
1.)使用ISO 8601 格式,它适用于任何语言环境或DateStyle
设置:
'2013-08-20 14:52:49'
You may still have to cast the string explicitly where the data type is no known a priori, depending on the use case:
根据用例,您可能仍然需要在数据类型未知的情况下显式转换字符串:
'2013-08-20 14:52:49'::timestamp
2.)Convert your string to timestamp
using to_timestamp()
with a matching template pattern:
2.)将您的字符串转换为timestamp
使用to_timestamp()
匹配的模板模式:
to_timestamp('20/8/2013 14:52:49', 'DD/MM/YYYY hh24:mi:ss')
回答by George Siggouroglou
To convert a string into a timestamp without timezone, for Postgresql, I use the above
要将字符串转换为没有时区的时间戳,对于 Postgresql,我使用上面的
SELECT to_timestamp('23-11-1986 09:30:00', 'DD-MM-YYYY hh24:mi:ss')::timestamp without time zone;