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 :)
精彩评论