我的约会日期如下:
Thu Nov 29 18:00:00 CST 2018
Thu Apr 26 01:00:00 BST 2018
我需要将其转换为oracle中的上午8点UTC。 我该怎么做呢 ? 这是一个字符串,而不是日期。
引荐链接处理的日期正确,没有可接受的答案。 在此先感谢
答案 0 :(得分:0)
因为它是字符串,所以可以使用regexp_replace
。
regexp_replace(nmuloc, '[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2} [A-Z]{3}', '08:00:00 GMT')
答案 1 :(得分:0)
Oracle设置
extension CalculatorVC : UITextFieldDelegate{
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let char = string.cString(using: String.Encoding.utf8)!
let isBackSpace = strcmp(char, "\\b")
if (isBackSpace == -92) {
//delete the second to last character
let text = textField.text!
let textDouble = text.replacingOccurrences(of: "%", with: "")
let doubleAdjusted = Double(textDouble)! / 10.0
//pad to three decimal places
let formatter = NumberFormatter()
formatter.maximumFractionDigits = 3
formatter.minimumFractionDigits = 3
formatter.roundingMode = .down
let num = NSNumber(value: doubleAdjusted)
let newText = formatter.string(from: num)!
textField.text = "\(newText)%"
}
return true
}
}
查询1 :
CREATE TABLE table_name ( datetime TIMESTAMP WITH TIME ZONE );
INSERT INTO table_name
SELECT TIMESTAMP '2018-11-29 18:00:00 CST' FROM DUAL UNION ALL
SELECT TIMESTAMP '2018-04-26 01:00:00 Europe/London' FROM DUAL UNION ALL
SELECT TIMESTAMP '2018-06-26 00:00:00 Europe/London' FROM DUAL;
将其从您的时区转换为UTC datetime AS TIME ZONE 'UTC'
将其截断为UTC日期的开始(并且也将其转换为日期)TRUNC()
将其恢复为时间戳记CAST( ... AS TIMESTAMP )
将其设置为UTC时区的时间戳记FROM_TZ( ..., 'UTC' )
,直到早上8点。赞:
INTERVAL '8' HOUR
输出:
SELECT FROM_TZ(
CAST(
TRUNC( datetime AT TIME ZONE 'UTC' )
AS TIMESTAMP
),
'UTC'
) + INTERVAL '8' HOUR AS utc_date_at_8am_utc
FROM table_name;
注意:这会在截断之前将UTC_DATE_AT_8AM_UTC
--------------------------------
30-NOV-18 08.00.00.000000 AM UTC
26-APR-18 08.00.00.000000 AM UTC
25-JUN-18 08.00.00.000000 AM UTC
转换为2018-06-26 00:00:00 BST
。因此它将是同一UTC日期(但不一定是本地时区的同一天)。
查询2
如果这是一个问题,那么只需删除初始时区转换即可:
2018-06-25 23:00:00 UTC
输出:
SELECT FROM_TZ(
CAST(
TRUNC( datetime )
AS TIMESTAMP
),
'UTC'
) + INTERVAL '8' HOUR AS date_at_8am_utc
FROM table_name