+ Start a Discussion
Narendra Reddy GopavaramNarendra Reddy Gopavaram 

Get time value based on billingstate in account using apex?

Hi All,

Need to display time value in account detail page based in billingstate. I have tried below code but final output getting in seconds, but i want to display complete time based on billing state.
 
@AuraEnabled
public static String gettime(String accId) 
{
Account acc =[SELECT id,name,BillingStreet,BillingCity,BillingState,BillingCountry,BillingLatitude,BillingLongitude,Time_Zone__c FROM Account WHERE Id=:accId];
Timezone tz = Timezone.getTimeZone(acc.Time_Zone__c);
DateTime dtpre = DateTime.newInstanceGMT(2000, 11, 1, 0, 0, 0);
String dt= String.valueof(tz.getOffset(dtpre));
return dt;
}
Output:  -18000000

I need to display in mm/dd/yyyy hh:mm:ss based on billing state. 

There is an option to get time value using google maps api, but it is paid service.

Thanks in Advance...
ANUTEJANUTEJ (Salesforce Developers) 
Hi  Narendra,

As mentioned in below links: 

>> http://bdunagan.com/2016/12/28/salesforce-tip-us-timezones/

>> https://www.biswajeetsamal.com/blog/formula-field-to-find-time-zone-from-state-field-in-salesforce/

One way is to have a formula field that gives timezone based on account billing State.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Narendra Reddy GopavaramNarendra Reddy Gopavaram
Hi Anutej,

Thanks for your suggetion.

In account i have already created Time_Zone__c formula field with same reference, with this i am getiitng output as: -18000000.

But i need to get date and time for any country.

Thanks.