<c:UserLocalDateTime value="{!NOW()}" format="EEE MMM d kk:mm:ss z yyyy" />
Last active
August 17, 2018 14:35
-
-
Save SalesforceBobLightning/995773e2b213254c458005044eb23ad3 to your computer and use it in GitHub Desktop.
Custom Visualforce Component to display DateTime with User TimeZone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <apex:component access="global" controller="UserLocalDateTimeController">{!FormattedDatetime} | |
| <apex:attribute assignTo="{!dateTimeValue}" description="The DateTime value to be rendered" name="value" type="DateTime"></apex:attribute> | |
| <apex:attribute assignTo="{!dateTimeFormat}" description="The format to use for the DateTime value to be rendered" name="format" type="String"></apex:attribute> | |
| </apex:component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UserLocalDateTimeController { | |
| public DateTime dateTimeValue { get; set; } | |
| public String dateTimeFormat { get; set; } | |
| public String getFormattedDatetime() { | |
| if (dateTimeValue == null) return ''; | |
| TimeZone tz = UserInfo.getTimeZone(); | |
| return dateTimeValue.format(dateTimeFormat, tz.toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment