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 = system.now();
String TimeZones = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
List<String> lststrsplit = TimeZones.substring(12,TimeZones.length()).split('\\(',2);
System.debug('Printing--lststrsplit-'+lststrsplit);
string strTimeZone = lststrsplit[1].substring(0,lststrsplit[1].length()-1);
System.debug('Printing--strTimeZone-'+strTimeZone);
system.debug(CurentTime+'abc#');
string strCurrentTime = CurentTime.format('YYYY-MM-dd HH:mm:ss', strTimeZone);
Datetime dateCurrentTime = Datetime.valueof(strCurrentTime);
System.debug('Printing--dateCurrentTime-'+dateCurrentTime);


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 -'+system.today());

System.debug('Printing---'+dt);

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}" />

</apex:outputText>