moikkakoikka Posted February 16, 2021 Share Posted February 16, 2021 HELP! I'm having problems with date. My site is in Finnish, and I don't want to hide months. I'd like to show a number instead of month: e.g. 12.3.2021. How I can make this happen? Blog summary blockId":"6fef3f5ae4cc9f0a1af1 blogs <time class="Blog-meta-item Blog-meta-item--date" datetime="2020-12-08" id="yui_3_17_2_1_1613466147605_439">8 December 2020</time> and blog page <time class="Blog-meta-item Blog-meta-item--date" datetime="2020-12-08">8 December 2020</time> Best regards, Katja Link to comment
moikkakoikka Posted February 16, 2021 Author Share Posted February 16, 2021 Template is Stella Link to comment
ArminB Posted February 16, 2021 Share Posted February 16, 2021 I'm afraid that involves some scripts but this addresses a quite similar issue: About Armin:Squarespace Expert Profile: https://www.squarespace.com/designer/profile/3649084Website: www.braunsberger-media.comLeaders Lodge: See my Profile Link to comment
moikkakoikka Posted February 16, 2021 Author Share Posted February 16, 2021 7 hours ago, ArminB said: I'm afraid that involves some scripts but this addresses a quite similar issue: OMG!!! I made it work. I fixed a little bit of the script I found: now the date is fully numeric and formed DD/MM/YYYY JESSSSS! ArminB 1 Link to comment
moikkakoikka Posted February 16, 2021 Author Share Posted February 16, 2021 (edited) Quote <script> document.addEventListener("DOMContentLoaded", function(event) { //Figure out context (blog-post or not?) var dateMeta = document.querySelector('[itemprop=datePublished]'); if (dateMeta != null) { //Handle blog post date var publishedDate = new Date(dateMeta.content); var dateElem = document.querySelector('time span'); updateDateElement(dateElem, publishedDate); } else { //Handle all dates on page var times = document.querySelectorAll('time'); for (var i = 0; i < times.length; i++) { var dateElem = times[i]; var publishedDate = new Date(dateElem.innerHTML); updateDateElement(dateElem, publishedDate); } } }); function updateDateElement(elem, date) { //Construct new display string //If you want a different localization, you can change the 'en-US'. //You can also type in undefined insteath of 'en-US' and let the device choose. var dateFormat = { year: 'numeric', month: 'numeric', day: 'numeric' }; var newFormat = date.toLocaleDateString('en-GB', dateFormat); //Assign new string elem.textContent = newFormat; } </script> This worked 🙂 Edited February 16, 2021 by moikkakoikka Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment