开发者

How to extract time for local time zone

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜