Jump to content

24h format

Recommended Posts

Posted
3 hours ago, estloris said:

Site URL: https://www.hrselts.ee/uritused/h2h-meet-up-synlab

Hi!

Is there still no possibility of customizing the format to 24 hours, at least with the code?

I appreciate any help you can provide.

This one?

image.thumb.png.f094f2d70148979f82e072cff715326d.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Posted

@estloris You can use this code to Website Tools > Code Injection > Footer

<script src="https://stevenlevithan.com/assets/misc/date.format.js"></script>
<script>
	document.addEventListener('DOMContentLoaded', function() {
      var timeformat = "H:MM";
     
      var eventTime = document.querySelectorAll("time[datetime][class*=event-time]");
            for (var i = 0; i < eventTime.length; i++) {
                  console.log(eventTime[i].getAttribute("datetime") + " " + eventTime[i].innerText);
                var d = new Date(eventTime[i].getAttribute("datetime") + " " + eventTime[i].innerText);

                eventTime[i].innerHTML = d.format(timeformat); 
            }
      var eventTimeSummary = document.querySelectorAll(".summary-metadata-item--event-time");
            for (var i = 0; i < eventTimeSummary.length; i++) {
                  var _24hrs = eventTimeSummary[i].querySelector(".event-time-24hr");
                  var _12hrs = eventTimeSummary[i].querySelector(".event-time-12hr");
                  _12hrs.innerHTML = _24hrs.innerHTML;
            }
  });


</script>

image.png.fe947b062419156f967e5d196f71137c.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted

Thank you a lot, @tuanphan

I checked it again and discovered that I only have a 24-hour format in Chrome. In Safari, it doesn't work for some reason 😞 I tried to delete browsing data, but it didn't help. It's strange 🙂 

I have discovered that I also have a 12h format in the Summary block, even in Chrome. Does it need to be changed separately?

Posted
On 10/21/2024 at 3:22 PM, estloris said:

Thank you a lot, @tuanphan

I checked it again and discovered that I only have a 24-hour format in Chrome. In Safari, it doesn't work for some reason 😞 I tried to delete browsing data, but it didn't help. It's strange 🙂 

I have discovered that I also have a 12h format in the Summary block, even in Chrome. Does it need to be changed separately?

This code should work with Summary.

Try this new code

<script src="https://stevenlevithan.com/assets/misc/date.format.js"></script>
<script>
	document.addEventListener('DOMContentLoaded', function() {
		var timeformat = "H:MM";
     
		var eventTime = document.querySelectorAll("time[datetime][class*=event-time]");
		for (var i = 0; i < eventTime.length; i++) {
			var datePart = eventTime[i].getAttribute("datetime");
			var timePart = eventTime[i].innerText;
			var isoString = datePart + "T" + timePart;
			var d = new Date(isoString);

			if (!isNaN(d.getTime())) {
				eventTime[i].innerHTML = d.format(timeformat);
			}
		}

		var eventTimeSummary = document.querySelectorAll(".summary-metadata-item--event-time");
		for (var i = 0; i < eventTimeSummary.length; i++) {
			var _24hrs = eventTimeSummary[i].querySelector(".event-time-24hr");
			var _12hrs = eventTimeSummary[i].querySelector(".event-time-12hr");
			_12hrs.innerHTML = _24hrs.innerHTML;
		}
	});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 10/28/2024 at 5:35 PM, estloris said:

Thank you once again, @tuanphan 🙂

The code still has no effect. 😞 It's applied now. Can you see 24h format? Maybe it's something with my browser.

Add this code under

<style>
  span.event-time-localized {
    display: none !important;
}

span.event-time-24hr {
    display: inline-block !important;
}
</style>

image.png.24337723a1f5f53994f45ccc05f9220b.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 10/30/2024 at 4:23 PM, tuanphan said:

Add this code under

<style>
  span.event-time-localized {
    display: none !important;
}

span.event-time-24hr {
    display: inline-block !important;
}
</style>

image.png.24337723a1f5f53994f45ccc05f9220b.png

Change the code to this

<style>
  .summary-v2-block span.event-time-localized {
    display: none !important;
}

.summary-v2-block span.event-time-24hr {
    display: inline-block !important;
}
</style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted

Hello, @tuanphan 🙂

It drives me crazy 😄 ahahaha. Sorry for torturing you 🙂

  • The time in summary is in a 24-hour format. Great!
  • Time in the event itself is back, but still in a 12-hour format 🤦🏻‍♂️

For double check — I have this code inserted

<script src="https://stevenlevithan.com/assets/misc/date.format.js"></script>
<script>
	document.addEventListener('DOMContentLoaded', function() {
		var timeformat = "H:MM";
     
		var eventTime = document.querySelectorAll("time[datetime][class*=event-time]");
		for (var i = 0; i < eventTime.length; i++) {
			var datePart = eventTime[i].getAttribute("datetime");
			var timePart = eventTime[i].innerText;
			var isoString = datePart + "T" + timePart;
			var d = new Date(isoString);

			if (!isNaN(d.getTime())) {
				eventTime[i].innerHTML = d.format(timeformat);
			}
		}

		var eventTimeSummary = document.querySelectorAll(".summary-metadata-item--event-time");
		for (var i = 0; i < eventTimeSummary.length; i++) {
			var _24hrs = eventTimeSummary[i].querySelector(".event-time-24hr");
			var _12hrs = eventTimeSummary[i].querySelector(".event-time-12hr");
			_12hrs.innerHTML = _24hrs.innerHTML;
		}
	});
</script>
<style>
  .summary-v2-block span.event-time-localized {
    display: none !important;
}

.summary-v2-block span.event-time-24hr {
    display: inline-block !important;
}
</style>

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.