开发者

How to extract time for local time zone

开发者 https://www.devze.com 2023-02-21 01:52 出处:网络
Hi All I want to extract time for my local time zone which i have set in my personal information likeconsider apex code below:

Hi All I want to extract time for my local time zone which i have set in my personal information

like consider apex code below:

DateTime cDT = system.Now();

String localDateTime = cDT.format();

now localDateTime will be like 4/1/2011 4:22 PM

I want to extract 4:22 PM out of this

One method given in salesforce documentation is hour,minute methods. But this method takes datetime as argument. But our format method returnes a string.

T开发者_StackOverflowhe solution may be convert the string returned by format method to datetime type. But could not. i tried parse method. it converted my local time back to GMT Time. Secondly i tried valueOf Method. But it accepts string in a specific format.

Please help me solving this problem. I have tries from my side. searched on net. but got no solution


I have got help from some other community and posting the answer for help of coders

To extract Time :
DateTime cDT = system.Now();
String localTime = cDT.format('h:mm a');

Similarly Date can be Extracted :
DateTime cDT = system.Now();
String localDate = cDT.format('d-MM-yyyy ');

Enjoy :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号