<?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: Json Date Conversion in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094268#M4518409</link>
    <description>&lt;P&gt;Did you try this ? &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/**
 * Converts milliseconds format to  
 * @param date milliseconds
 */
 function : setDateFromMillisecond(var s){
     var str = "/Date(253402300799000)";
     var res = str.substring(6, 21);
     var date = new Date(Number(res));
 }
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Is millisecond the only type of input for data ? &lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 22:39:51 GMT</pubDate>
    <dc:creator>smarchesini</dc:creator>
    <dc:date>2019-10-01T22:39:51Z</dc:date>
    <item>
      <title>Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaq-p/12094267</link>
      <description>&lt;P&gt;Hi All, &lt;/P&gt;
  &lt;P&gt; I am getting a response of date in Json format /Date(253402300799000) which I want to show in as a normal date on my UI (dd/mm/yyyy). I have written a function to convert it but for certain scenarios it is failing like for date 9999-12-31 &amp;amp; 1900-01-01.&lt;/P&gt;
  &lt;P&gt;When I convert the above one it is giving me the date 1-1-10000 &amp;amp; 1-1-2040.&lt;/P&gt;
  &lt;P&gt;here is the function which I have Written :&lt;/P&gt;
  &lt;P&gt;for (var i = 0; i &amp;lt; oData.date.length; i++) &lt;/P&gt;
  &lt;P&gt;{ &lt;/P&gt;
  &lt;P&gt;var oDate = oData.date[i].DATE.match(/\d+/g); &lt;/P&gt;
  &lt;P&gt;var oDate1 = new Date(parseInt(oDate)); &lt;/P&gt;
  &lt;P&gt;var sDate = oDate1.getMonth() + 1 + "-" + oDate1.getDate() + "-" + oDate1.getFullYear(); &lt;/P&gt;
  &lt;P&gt;oData.date[i].DATE = sDate;&lt;/P&gt;
  &lt;P&gt; }&lt;/P&gt;
  &lt;P&gt;Note : I am using xsoData. &lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 08:51:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaq-p/12094267</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-09-30T08:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094268#M4518409</link>
      <description>&lt;P&gt;Did you try this ? &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/**
 * Converts milliseconds format to  
 * @param date milliseconds
 */
 function : setDateFromMillisecond(var s){
     var str = "/Date(253402300799000)";
     var res = str.substring(6, 21);
     var date = new Date(Number(res));
 }
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Is millisecond the only type of input for data ? &lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 22:39:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094268#M4518409</guid>
      <dc:creator>smarchesini</dc:creator>
      <dc:date>2019-10-01T22:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094269#M4518410</link>
      <description>&lt;P&gt;Hi &lt;A href="https://answers.sap.com/users/266195/smarches.html"&gt;Sebastiano&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;I have tried it, but it is giving the wrong date as:-"Sat Jan 01 10000 05:29:59 GMT+0530 (India Standard Time)". &lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 11:53:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094269#M4518410</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-10-08T11:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094270#M4518411</link>
      <description>&lt;P&gt;Sorry Sandeep, &lt;BR /&gt;&lt;BR /&gt;what's time you needed ? &lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 15:22:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094270#M4518411</guid>
      <dc:creator>smarchesini</dc:creator>
      <dc:date>2019-10-08T15:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094271#M4518412</link>
      <description>&lt;P&gt;Hi Sandeep,&lt;/P&gt;&lt;P&gt;The issue is not with your code but seems like there is some internal conversion happening from the back-end when the date is being returned.&lt;/P&gt;&lt;P&gt;The value which is being returned ( /Date(253402300799000)) results to date as Jan 01 10000.&lt;/P&gt;&lt;P&gt;Are there any chances that those 2 dates would be returned from your back-end ? If no, then probably you can ignore these.&lt;/P&gt;&lt;P&gt;Else you need to handle these explicitly when you date object results in these kind of dates.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;vaibhav&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 05:26:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094271#M4518412</guid>
      <dc:creator>mvaibhav</dc:creator>
      <dc:date>2019-10-09T05:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Json Date Conversion</title>
      <link>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094272#M4518413</link>
      <description>&lt;P&gt;JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with &lt;A href="http://net-informations.com/jq/iq/jdate.htm"&gt;dates in JSON&lt;/A&gt; and really JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows: &lt;/P&gt;&lt;P&gt;var jsonDate = new Date(1297246301973); &lt;/P&gt;&lt;P&gt; Then let's convert it to js format: &lt;/P&gt;&lt;P&gt;var date = new Date(parseInt(jsonDate.substr(6))); &lt;/P&gt;&lt;P&gt;The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor . &lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 08:51:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-date-conversion/qaa-p/12094272#M4518413</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-08-02T08:51:39Z</dc:date>
    </item>
  </channel>
</rss>

