function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Forum 007SFDC Forum 007 

time in hh:mm format

Hi ,

 

 I have a date/time field which i am fetching dynamically , i want the time field to be displayed in hh:mm format, below is my code written for time

 

 

if(callReppaMap.get(ac.personContactId)!=null){
                        paDet.crdate=string.valueof(callReppaMap.get(ac.pe

rsonContactId).Date__c.time());
                    }else{
                        paDet.crdate='';

                    }

 

 

Please help me out to fetch the time in hh:mm format

 

 

Thanks in Advance

bob_buzzardbob_buzzard

Use the format method of date/time to get the text representation you want.

 

E.g.

 

DateTime dt=System.now();

String dtStr=dt.format('HH:mm');

 

The format characters are those from Java simpledateformat, which you can find more information on at:

 

http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

SFDC Forum 007SFDC Forum 007

Hi,

 

I have used the same code of urs , still displays with milliseconds, ie: 09:53:00.000Z

 

 

below is my code

 

 if(callReppaMap.get(ac.personContactId)!=null){
                       DateTime dt=System.now();
                       String dtStr=dt.format('HH:mm');
                       dtStr=string.valueof(callReppaMap.get(ac.personContactId).Date__c.time());
                        paDet.crdate=string.valueof(callReppaMap.get(ac.personContactId).Date__c.time());
                    }else{
                        paDet.crdate='';

                    }

 

Thanks in Advance

bob_buzzardbob_buzzard

I gave you an example of how to convert a date time into a string of that format.  You can't just paste this in and expect unrelated code to change its behaviour.  You'll need to convert your date time instance to a string using that mechanism.

SFDC Forum 007SFDC Forum 007

i have converted my date to string format only... it isint giving

bob_buzzardbob_buzzard

The code you posted above isn't doing that.

SFDC Forum 007SFDC Forum 007

nopes didnt do that....

bob_buzzardbob_buzzard

I'm not sure what your last post means.  Didn't do what?

 

If you have changed your code from the last post, perhaps you should consider posting the latest version.

SFDC Forum 007SFDC Forum 007

nopes i meant that time part is not being fetched as per my format needed, i tried with the changes said bu you, If you can help me how to do it would be great :)

bob_buzzardbob_buzzard

The code you posted isn't using my code - you've simply copied my example into your class.  You need to change your code to format your date/time.

 

If you have changed the code from the last that you posted, please post the latest version.