You need to sign in to do that
Don't have an account?
sonam
Display date in User's timezone in a given Format
Please help
1. Initially 5hours were added to the GMT.
But , when i give a future date ...... i get the current date.
public static String printDate(Datetime Value,String format) { datetime systemDate = datetime.now(); String timeZone = UserInfo.getTimeZone().getID(); System.debug('getTimeZone-----------------'+timeZone); if(!systemDate.isSameDay(Value)) { System.debug('not current date'); Value = Value.addHours(5); } return Value.format(format); }
2. I tried to pass the timezone but I am unable to correct it.
It gives me the previous date by the following code.
public static String printDate(Datetime Value,String format) { datetime systemDate = datetime.now(); String timeZone = UserInfo.getTimeZone().getID(); System.debug('getTimeZone-----------------'+timeZone); if(!systemDate.isSameDay(Value)) { System.debug('date --------'+ Value); System.debug('not current date'); System.debug('getTimeZone-----------------'+timeZone); System.debug('value is time zone>>>'+UserInfo.getTimeZone().getDisplayName()); String ValueLocalDate = Value.format(format,timeZone); System.debug('ValueLocalDate-----------------'+ValueLocalDate); return ValueLocalDate ; } return Value.format(format); }
I checked the debug logs to find that the timestamp is taken as 2013-01-05 00:00:00 and not the original time
Time is taken as 00:00:00
Thanks in advance.
What is the value of your format and value parameters when your method is called?
1.Value is dateTime and
2.The format is 'MMMMM dd, yyyy' but its passed along with the date as functionName(Date ,'MMMMM dd, yyyy');
1) By dateTime do you mean dateTime.now()?
2) Might want to print the Hours with your debug. e.g. YYYY-MM-DDThh:mm:ss+hh:mm