<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Timestamp string conversion / from_utc_timestamp in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Timestamp-string-conversion-from-utc-timestamp/m-p/333257#M231391</link>
    <description>&lt;P&gt;I have used CDP (Hive-3.1.3000) to run below queries.&lt;BR /&gt;&lt;BR /&gt;1. I am getting value instead of null when i execute below command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_utc_timestamp(from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssXXX"),"America/New_York");
+------------------------+
| _c0 |
+------------------------+
| 2021-10-02 20:00:00.0 |
+------------------------+&lt;/LI-CODE&gt;&lt;P&gt;2. from_utc_timestamp does not give output along with TimeZone as it is internally returning LocalDateTime which does not have TZ information&lt;/P&gt;&lt;P&gt;GenericUDFFromUtcTimestamp.java&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Now output this timestamp's millis value to the equivalent toTz.
Timestamp result = Timestamp.valueOf(
fromTs.getZonedDateTime().withZoneSameInstant(toTz.toZoneId()).toLocalDateTime().toString());&lt;/LI-CODE&gt;&lt;P&gt;LocalDateTime&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//-----------------------------------------------------------------------
/**
* Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30}.
* &amp;lt;p&amp;gt;
* The output will be one of the following ISO-8601 formats:
* &amp;lt;ul&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSS}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSS}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS}&amp;lt;/li&amp;gt;
* &amp;lt;/ul&amp;gt;
* The format used will be the shortest that outputs the full value of
* the time where the omitted parts are implied to be zero.
*
* @return a string representation of this date-time, not null
*/
@Override
public String toString() {
return date.toString() + 'T' + time.toString();
}&lt;/LI-CODE&gt;&lt;P&gt;3. Converting timestamp to the format "2021-10-03T15:10:00-04:00" does not seem to be possible with existing Hive UDF functions instead 'Z' notation can be used&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssXXX");
+-----------------------+
| _c0 |
+-----------------------+
| 2021-10-03T15:10:00Z |
+-----------------------+&lt;/LI-CODE&gt;&lt;P&gt;Or&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssZZZ");
+---------------------------+
| _c0 |
+---------------------------+
| 2021-10-03T15:10:00+0000 |
+---------------------------+&lt;/LI-CODE&gt;&lt;P&gt;Reference: &lt;A href="https://stackoverflow.com/questions/34723683/simpledateformat-ignores-xxx-if-timezone-is-set-to-utc" target="_blank"&gt;https://stackoverflow.com/questions/34723683/simpledateformat-ignores-xxx-if-timezone-is-set-to-utc&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jan 2022 17:38:50 GMT</pubDate>
    <dc:creator>tarak271</dc:creator>
    <dc:date>2022-01-05T17:38:50Z</dc:date>
    <item>
      <title>Timestamp string conversion / from_utc_timestamp</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Timestamp-string-conversion-from-utc-timestamp/m-p/332599#M231206</link>
      <description>&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;I need to convert 2021-10-03 15:10:00.0 as 2021-10-03T15:10:00-04:00&lt;/P&gt;&lt;P&gt;I tried with.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from_utc_timestamp(from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssXXX"),"America/New_York")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got Null value&lt;/P&gt;&lt;P&gt;Any suggestions please&lt;/P&gt;</description>
      <pubDate>Sun, 19 Dec 2021 16:55:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Timestamp-string-conversion-from-utc-timestamp/m-p/332599#M231206</guid>
      <dc:creator>AKRAM</dc:creator>
      <dc:date>2021-12-19T16:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp string conversion / from_utc_timestamp</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Timestamp-string-conversion-from-utc-timestamp/m-p/333257#M231391</link>
      <description>&lt;P&gt;I have used CDP (Hive-3.1.3000) to run below queries.&lt;BR /&gt;&lt;BR /&gt;1. I am getting value instead of null when i execute below command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_utc_timestamp(from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssXXX"),"America/New_York");
+------------------------+
| _c0 |
+------------------------+
| 2021-10-02 20:00:00.0 |
+------------------------+&lt;/LI-CODE&gt;&lt;P&gt;2. from_utc_timestamp does not give output along with TimeZone as it is internally returning LocalDateTime which does not have TZ information&lt;/P&gt;&lt;P&gt;GenericUDFFromUtcTimestamp.java&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Now output this timestamp's millis value to the equivalent toTz.
Timestamp result = Timestamp.valueOf(
fromTs.getZonedDateTime().withZoneSameInstant(toTz.toZoneId()).toLocalDateTime().toString());&lt;/LI-CODE&gt;&lt;P&gt;LocalDateTime&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//-----------------------------------------------------------------------
/**
* Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30}.
* &amp;lt;p&amp;gt;
* The output will be one of the following ISO-8601 formats:
* &amp;lt;ul&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSS}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSS}&amp;lt;/li&amp;gt;
* &amp;lt;li&amp;gt;{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS}&amp;lt;/li&amp;gt;
* &amp;lt;/ul&amp;gt;
* The format used will be the shortest that outputs the full value of
* the time where the omitted parts are implied to be zero.
*
* @return a string representation of this date-time, not null
*/
@Override
public String toString() {
return date.toString() + 'T' + time.toString();
}&lt;/LI-CODE&gt;&lt;P&gt;3. Converting timestamp to the format "2021-10-03T15:10:00-04:00" does not seem to be possible with existing Hive UDF functions instead 'Z' notation can be used&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssXXX");
+-----------------------+
| _c0 |
+-----------------------+
| 2021-10-03T15:10:00Z |
+-----------------------+&lt;/LI-CODE&gt;&lt;P&gt;Or&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;0: jdbc:hive2://hs2&amp;gt; select from_unixtime(unix_timestamp('2021-10-03 15:10:00.0', "yyyy-MM-dd HH:mm:ss.S"),"yyyy-MM-dd'T'HH:mm:ssZZZ");
+---------------------------+
| _c0 |
+---------------------------+
| 2021-10-03T15:10:00+0000 |
+---------------------------+&lt;/LI-CODE&gt;&lt;P&gt;Reference: &lt;A href="https://stackoverflow.com/questions/34723683/simpledateformat-ignores-xxx-if-timezone-is-set-to-utc" target="_blank"&gt;https://stackoverflow.com/questions/34723683/simpledateformat-ignores-xxx-if-timezone-is-set-to-utc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 17:38:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Timestamp-string-conversion-from-utc-timestamp/m-p/333257#M231391</guid>
      <dc:creator>tarak271</dc:creator>
      <dc:date>2022-01-05T17:38:50Z</dc:date>
    </item>
  </channel>
</rss>

