Jump to content

Changing event page time from "AM/PM" to "a.m./p.m"

Recommended Posts

Posted

Like it says in the title. Is this possible? I have a client who is integrating their site into a larger collection of sites and wants all times to appear with "a.m. or p.m." instead of the default AM and PM that Squarespace events pages have. Let me know!

  • 2 years later...
Posted
On 2/7/2022 at 7:46 AM, tuanphan said:

You mean make it lowercase & add dot between a-m, p-m??

Hi @tuanphan! I have a client who actually wants to change this on all events from “AM/PM” to “a.m. / p.m.” Is there a way to add this punctuation with code? Thanks! (The site is https://wearecap.org/events)

PATRICK GARR

🚀Helping artists become creative entrepreneurs 

w. PGCreativeDesigns.com

e. Hello@PGCreativeDesigns.com

Posted

@pgcreativedesigns Hi! You can add this code in Website > Pages > Website Tools > Code Injection > Header to change from “AM/PM” to “a.m. / p.m.” 

<script>
document.addEventListener("DOMContentLoaded", function() {
  const timeElements = document.querySelectorAll('.event-time-localized-start, .event-time-localized-end');
  function convertTimeFormat(timeElement) {
    let timeText = timeElement.innerHTML;
    timeText = timeText.replace('AM', 'a.m.').replace('PM', 'p.m.');
    timeElement.innerHTML = timeText;
  }
  
  timeElements.forEach(time => convertTimeFormat(time));
});
</script>

 

If my comments were useful, please like or mark my solution as answer so others can scroll to it quickly. 

Sam
Web Developer & Digital Designer

 Did you find my contribution helpful? Buy me a coffee?

Posted
2 hours ago, Lesum said:

@pgcreativedesigns Hi! You can add this code in Website > Pages > Website Tools > Code Injection > Header to change from “AM/PM” to “a.m. / p.m.” 

<script>
document.addEventListener("DOMContentLoaded", function() {
  const timeElements = document.querySelectorAll('.event-time-localized-start, .event-time-localized-end');
  function convertTimeFormat(timeElement) {
    let timeText = timeElement.innerHTML;
    timeText = timeText.replace('AM', 'a.m.').replace('PM', 'p.m.');
    timeElement.innerHTML = timeText;
  }
  
  timeElements.forEach(time => convertTimeFormat(time));
});
</script>

 

Hi @Lesum! Thank you so much - unfortunately this didn't work. There seems to be something wrong with the initial syntax of the script. Is there something missing? Thanks!

PATRICK GARR

🚀Helping artists become creative entrepreneurs 

w. PGCreativeDesigns.com

e. Hello@PGCreativeDesigns.com

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.