Multiple timezones displayed in confluence

We are a multi-national company and I am going through the possibility of having our default home page be confluence.  Currently in our html default home page it will show each region's local time.  I have tried to write a macro to do this but got stuck along the way.  The following code will display the local timezone: 

$action.dateFormatter.formatGivenString("HH:mm", $content.currentDate) 

But I cannot figure out how to get it to display the various other timezones.    I have seen that there is a tz parameter for dateFormatter but I could not find any examples of usage.

5 answers

1 accepted

Hi Robert,

I was bored, so I decided to try it out.  It's a bit of a hack and it's maybe not the easiest way to do it, but at least it works smile

## @param Timezone:title=Time Zone|required=true|type=enum|,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
#set ( $timezones = $action.dateFormatter.timeZone.sortedTimeZones )
#set ( $selectedTimezone = $action.dateFormatter.timeZone.default.wrappedTimeZone )
#foreach ( $timezone in $timezones )
  #if ( $timezone == $paramTimezone )
    #set ( $selectedTimezone = $timezone.wrappedTimeZone )
#set ( $calendar = $action.dateFormatter.calendar.getInstance($selectedTimezone) )
#set ( $hour = $calendar.get(10) )
#set ( $minute = $calendar.get(12) )
#if ( $hour < 10 )
  #set ( $hour = "0" + $hour )
#if ( $minute < 10 )
  #set ( $minute = "0" + $minute )
<p>$selectedTimezone.getDisplayName(false, 0): $hour:$minute</p>


This works like a champ! Thank you.

Sorry where do you apply this? Do you need to create a new macro? edit the page in source editor? Sorry for the basic question, i'm pretty new to confluence.

Yes, you need to create a new user macro (You must be an administrator; click the Gear icon at the top of the screen, then General Configuration, enter your password, and find "User Macros" on the left side of the screen). You just give the user macro any name you want (no spaces) and a title (what will be displayed in the macro editor). If you want so that not everybody can see it, choose the visibility under the name. Everything else can stay blank/as it is. Once you save it, the macro should be available to insert on a page.

0 votes
Davin Studer Community Champion Nov 10, 2014

What do you want to display in multiple times zones? Is it the create and modified date? Comments? Something within the page body? All of the above?

Good point David! I guess I need to be more clear. I want to display the time. E.G.: CST: 13:45 EST: 14:45 CEST: 20:45 KST: 04:48 ...

Almost 4 years late :) But change the $hour line as:

#set ( $hour = $calendar.get(11) )

0 votes
Davin Studer Community Champion Nov 10, 2014

For what portions of the page are you wanting this multiple time zone stuff on?

What portions? Not sure I understand the question. Ideally I would want a macro that takes as a single parameter a time zone, and outputs the current time in that time zone. I have that all but I cannot find a good example of setting the timezone in dateFormatter.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

419 views 2 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you