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.
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
## @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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For what portions of the page are you wanting this multiple time zone stuff on?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Almost 4 years late :) But change the $hour line as:
#set ( $hour = $calendar.get(11) )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.