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|enumValues=time.zone.user_time_zone,time.zone.HST,time.zone.AST,time.zone.America.Los.Angeles,time.zone.America.Denver,time.zone.America.Mazatlan,time.zone.America.Phoenix,time.zone.America.Belize,time.zone.America.Chicago,time.zone.America.Mexico.City,time.zone.America.Regina,time.zone.America.Bogota,time.zone.America.Indianapolis,time.zone.America.New.York,time.zone.America.Caracas,time.zone.America.Halifax,time.zone.America.Santiago,time.zone.America.St.Johns,time.zone.America.Buenos.Aires,time.zone.America.Godthab,time.zone.America.Sao.Paulo,time.zone.Atlantic.South.Georgia,time.zone.Atlantic.Azores,time.zone.Atlantic.Cape.Verde,time.zone.Africa.Casablanca,time.zone.Europe.Dublin,time.zone.GMT,time.zone.ECT,time.zone.Europe.Belgrade,time.zone.Europe.Berlin,time.zone.Europe.Paris,time.zone.Europe.Warsaw,time.zone.Africa.Cairo,time.zone.Africa.Harare,time.zone.Asia.Jerusalem,time.zone.Europe.Athens,time.zone.Europe.Bucharest,time.zone.Europe.Helsinki,time.zone.Africa.Nairobi,time.zone.Asia.Baghdad,time.zone.Asia.Kuwait,time.zone.Asia.Tehran,time.zone.Asia.Baku,time.zone.Asia.Muscat,time.zone.Europe.Moscow,time.zone.Asia.Kabul,time.zone.Asia.Karachi,time.zone.Asia.Calcutta,time.zone.Asia.Colombo,time.zone.Asia.Katmandu,time.zone.Asia.Almaty,time.zone.Asia.Dhaka,time.zone.Asia.Yekaterinburg,time.zone.Asia.Rangoon,time.zone.Asia.Bangkok,time.zone.Asia.Hong.Kong,time.zone.Asia.Krasnoyarsk,time.zone.Asia.Kuala.Lumpur,time.zone.Asia.Taipei,time.zone.Australia.Perth,time.zone.Asia.Irkutsk,time.zone.Asia.Seoul,time.zone.Asia.Tokyo,time.zone.Australia.Adelaide,time.zone.Australia.Darwin,time.zone.Asia.Yakutsk,time.zone.Australia.Brisbane,time.zone.Australia.Hobart,time.zone.Australia.Sydney,time.zone.Pacific.Guam,time.zone.Asia.Vladivostok,time.zone.Pacific.Noumea,time.zone.Pacific.Auckland,time.zone.Pacific.Fiji,time.zone.Pacific.Apia,time.zone.Pacific.Tongatapu
#set ( $timezones = $action.dateFormatter.timeZone.sortedTimeZones )
#set ( $selectedTimezone = $action.dateFormatter.timeZone.default.wrappedTimeZone )
#foreach ( $timezone in $timezones )
  #if ( $timezone == $paramTimezone )
    #set ( $selectedTimezone = $timezone.wrappedTimeZone )
  #end
#end
#set ( $calendar = $action.dateFormatter.calendar.getInstance($selectedTimezone) )
#set ( $hour = $calendar.get(10) )
#set ( $minute = $calendar.get(12) )
#if ( $hour < 10 )
  #set ( $hour = "0" + $hour )
#end
#if ( $minute < 10 )
  #set ( $minute = "0" + $minute )
#end
<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