Oracle中的时区日期格式

时间:2016-11-28 10:00:29

标签: sql oracle datetime

我必须将SYSDATE日期转换为特定的日期格式。该格式必须是这样的:'2016-11-23T15:12:48Z'。我认为这是一种奇怪的日期格式,但这是我的要求。

这必须是在Web服务消息中发送的日期。

在Oracle(12c或11g)中,我有一些功能来转换这种特定格式的日期?感谢。

2 个答案:

答案 0 :(得分:4)

这将给你评论中提到的ISO-8601:

I/JSON Parser: <!DOCTYPE html>
                                                                          <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
                                                                          <!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
                                                                          <!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
                                                                          <!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
                                                                          <head>
                                                                          <title>Attention Required! | CloudFlare</title>
                                                                          <meta charset="UTF-8" />
                                                                          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                                                                          <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
                                                                          <meta name="robots" content="noindex, nofollow" />
                                                                          <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
                                                                          <link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" type="text/css" media="screen,projection" />
                                                                          <!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" type="text/css" media="screen,projection" /><![endif]-->
                                                                          <style type="text/css">body{margin:0;padding:0}</style>
                                                                          <!--[if lte IE 9]><script type="text/javascript" src="/cdn-cgi/scripts/jquery.min.js"></script><![endif]-->
                                                                          <!--[if gte IE 10]><!--><script type="text/javascript" src="/cdn-cgi/scripts/zepto.min.js"></script><!--<![endif]-->
                                                                          <script type="text/javascript" src="/cdn-cgi/scripts/cf.common.js"></script>


                                                                          </head>
                                                                          <body>
                                                                            <div id="cf-wrapper">
                                                                              <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
                                                                              <div id="cf-error-details" class="cf-error-details-wrapper">
                                                                                <div class="cf-wrapper cf-header cf-error-overview">
                                                                                  <h1 data-translate="challenge_headline">One more step</h1>
                                                                                  <h2 class="cf-subheadline"><span data-translate="complete_sec_check">Please complete the security check to access</span> laboneinside.com</h2>
                                                                                </div><!-- /.header -->

                                                                                <div class="cf-section cf-highlight cf-captcha-container">
                                                                                  <div class="cf-wrapper">
                                                                                    <div class="cf-columns two">
                                                                                      <div class="cf-column">
                                                                                        <div class="cf-highlight-inverse cf-form-stacked">
                                                                                          <form class="challenge-form" id="challenge-form" action="/cdn-cgi/l/chk_captcha" method="get">
                                                                            <script type="text/javascript" src="/cdn-cgi/scripts/cf.challenge.js" data-type="normal"  data-ray="308cf17ac17329be" async data-sitekey="6LfOYgoTAAAAAInWDVTLSc8Yibqp-c9DaLimzNGM" data-stoken="kvvwvLSUth2MQ7fsfXFwr9TjwkJ6pEiMAfiAhb7x9fVk7yqCvGMh-myXoKQuhQt_4MjgZHunito0fikCnHS-DFoymBKWm5gb3lnlB4dceb0"></script>
                                                                            <div class="g-recaptcha"></div>
                                                                            <noscript id="cf-captcha-bookmark" class="cf-captcha-info">
                                                                              <div><div style="width: 302px">
                                                                                <div>
                                                                                  <iframe src="https://www.google.com/recaptcha/api/fallback?k=6LfOYgoTAAAAAInWDVTLSc8Yibqp-c9DaLimzNGM&stoken=kvvwvLSUth2MQ7fsfXFwr9TjwkJ6pEiMAfiAhb7x9fVk7yqCvGMh-myXoKQuhQt_4MjgZHunito0fikCnHS-DFoymBKWm5gb3lnlB4dceb0" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
                                                                                </div>
                                                                                <div style="width: 300px; border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">
                                                                                  <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none;"></textarea>
                                                                                  <input type="submit" value="Submit"></input>
                                                                                </div>
                                                                              </div></div>
                                                                            </noscript>
                                                                          </form>

                                                                                        </div>
                                                                                      </div>

                                                                                      <div class="cf-column">
                                                                                        <div class="cf-screenshot-container">

                                                                                          <span class="cf-no-screenshot"></span>

                                                                                        </div>
                                                                                      </div>
                                                                                    </div><!-- /.columns -->
                                                                                  </div>
                                                                                </div><!-- /.captcha-container -->

                                                                                <div class="cf-section cf-wrapper">
                                                                                  <div class="cf-columns two">
                                                                                    <div class="cf-column">
                                                                                      <h2 data-translate="why_captcha_headline">Why do I have to complete a CAP
11-28 04:55:15.976 30265-30325/com.example.predator.labone E/log_tag: Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

如果你真的想要select to_char(systimestamp,'YYYY-MM-DD"T"hh24:mi:sstzh:tzm') isodt from dual; 而不是时区,你可以使用:

Z

答案 1 :(得分:4)

"Z" in the timestamp format you're after means "This is in UTC"开始,您应该首先确保您的sysdate以UTC格式返回。您可以使用systimestamp和sys_extract_utc()这样执行此操作:

select to_char(sys_extract_utc(systimestamp), 'yyyy-mm-dd"T"hh24:mi:ss"Z"') dt_as_utc
from dual;

DT_AS_UTC
--------------------
2016-11-28T10:33:49Z