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


Hi , 

My requirement is , i need to dispaly the current time, and depending on the current time 

i should be able to display previous 30 minutes ,previous 1 hour ,previous 2 hours to the current time and disaplay them in 

a dropdown ,


for eaxmple:

if the current time is 9:00 in the drop down i should be able to dispaly 

8:30 and 8:00 and 7:00 so on and it should alter depending upon the current itme

could anyone could help me with an example how would i achieve this


Thank You




This is a duplicate post please make sure that you do not post any duplication questions on discussion board. So I request you to please remove it.


For information regarding this post you can go to the following link:


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 



Richa KRicha K


In add this in your page :

    <apex:pageBlockSection columns="1" showHeader="false">
                    <apex:outputLabel value="Time Zone" for="tmt"></apex:outputLabel>
                    <apex:selectList id="mgr" Size="1" title="Time Zone">
                        <apex:selectOptions value="{!timet}"></apex:selectOptions>

 Add this in your class : You can make it more dynamic if you want,

   public List<selectOption> getTimet() 
        Datetime myDT =;
        String myDate = myDT.format('h:mm a');
        String myDate1 = myDT.addMinutes(-30).format('h:mm a');
        String myDate2 = myDT.addHours(1).format('h:mm a');
        String myDate3 = myDT.addHours(2).format('h:mm a');
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('', myDate ));
        options.add(new selectOption('', myDate1 ));
        options.add(new selectOption('', myDate2 ));
        options.add(new selectOption('', myDate3 ));
        return options;