{"id":2927,"date":"2018-12-06T12:58:15","date_gmt":"2018-12-06T10:58:15","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2927"},"modified":"2020-10-04T21:49:25","modified_gmt":"2020-10-04T19:49:25","slug":"sharepoint-changing-date-format-using-javascript","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2927","title":{"rendered":"Sharepoint : Changing date format using javascript"},"content":{"rendered":"<p>I would recommend to use : Moment.js library (<a href=\"http:\/\/momentjs.com\/\">link<\/a>)<\/p>\n<h3 id=\"format-dates\">Format Dates<\/h3>\n<pre><code class=\"language-js\">moment().format(<span class=\"string\">'MMMM Do YYYY, h:mm:ss a'<\/span>);<span class=\"comment\"> \/\/ December 6th 2018, 11:55:15 am<\/span>\nmoment().format(<span class=\"string\">'dddd'<\/span>);                   <span class=\"comment\"> \/\/ Thursday<\/span>\nmoment().format(<span class=\"string\">\"MMM Do YY\"<\/span>);              <span class=\"comment\"> \/\/ Dec 6th 18<\/span>\nmoment().format(<span class=\"string\">'YYYY [escaped] YYYY'<\/span>);    <span class=\"comment\"> \/\/ 2018 escaped 2018<\/span>\nmoment().format();                         <span class=\"comment\"> \/\/ 2018-12-06T11:55:15+01:00<\/span><\/code><\/pre>\n<h3 id=\"relative-time\">Relative Time<\/h3>\n<pre><code class=\"language-js\">moment(<span class=\"string\">\"20111031\"<\/span>, <span class=\"string\">\"YYYYMMDD\"<\/span>).fromNow();<span class=\"comment\"> \/\/ 7 years ago<\/span>\nmoment(<span class=\"string\">\"20120620\"<\/span>, <span class=\"string\">\"YYYYMMDD\"<\/span>).fromNow();<span class=\"comment\"> \/\/ 6 years ago<\/span>\nmoment().startOf(<span class=\"string\">'day'<\/span>).fromNow();       <span class=\"comment\"> \/\/ 12 hours ago<\/span>\nmoment().endOf(<span class=\"string\">'day'<\/span>).fromNow();         <span class=\"comment\"> \/\/ in 12 hours<\/span>\nmoment().startOf(<span class=\"string\">'hour'<\/span>).fromNow();      <span class=\"comment\"> \/\/ an hour ago\n\n===============================================\nhttps:\/\/msdn.microsoft.com\/fr-fr\/library\/ee532932(v=vs.94).aspx\n\n<\/span><\/code><\/pre>\n<pre>var myDate = new Date(\"1\/1\/1990\")\nmyDate.setMonth(myDate.getMonth() + 1);\n\nmyDate.setDate (myDate.getDate() - 1);\n\ndocument.write(myDate);\n\n\/\/ Output: Wed Jan 31 00:00:00 PST 1990\n===========================================================\nvar today = new Date(new Date().setHours(0,0,0,0));<\/pre>\n<pre><code class=\"language-js\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I would recommend to use : Moment.js library (link) Format Dates moment().format(&#8216;MMMM Do YYYY, h:mm:ss a&#8217;); \/\/ December 6th 2018, 11:55:15 am moment().format(&#8216;dddd&#8217;); \/\/ Thursday moment().format(&#8220;MMM Do YY&#8221;); \/\/ Dec 6th 18 moment().format(&#8216;YYYY [escaped]&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2857,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[284,363],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2927"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2927"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2927\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2857"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}