Thursday, 17 March 2016

How to convert any standard time to PST ?

As we already know based on user local and company info date time will be displayed by default.
However we need to convert date time from one format to another. Below is some code snippet for this .

DateTime CurentTime =;
String TimeZones = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
List<String> lststrsplit = TimeZones.substring(12,TimeZones.length()).split('\\(',2);
string strTimeZone = lststrsplit[1].substring(0,lststrsplit[1].length()-1);
string strCurrentTime = CurentTime.format('YYYY-MM-dd HH:mm:ss', strTimeZone);
Datetime dateCurrentTime = Datetime.valueof(strCurrentTime);

Thursday, 10 March 2016

How to Parse date in SFDC?

Date format used to vary from system to system.

In SFDC it is like YYYY-MM-DD -2016-03-10 00:00:00

Lets say date format is DD/MM/YYYY in other system, how will we store such date foramt ?

String s = '15/08/2014';
date dt = Date.Parse(s);
System.debug('Printing--today date -';


Out put will be

11:25:10.11 (12471791)|USER_DEBUG|[3]|DEBUG|Printing--today date -2016-03-10 00:00:00
11:25:10.11 (12560905)|USER_DEBUG|[5]|DEBUG|Printing---2014-08-15 00:00:00

Friday, 4 March 2016

How to format the Currency/number field ?

Sometimes we have to format the currency field based on user need. Here is code snippet which will help you to format the value.

<apex:outputText   value="{0, number, ###,##0.00}">
        <apex:param value="{!objectref.fieldname__c}" />