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
downloadingdownloading 

Time

Hi , 

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

i should be able to add 30 min , 1 hour , 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 

9:30 and 10:00 and 11: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

Navatar_DbSupNavatar_DbSup

Hi,


Try the below code as reference:


datetime nowDate=system.now();
Datetime myDT = Datetime.now();
String myDate = myDT.format('h:mm a');
system.debug('@@@@@@@@@@@@@@@@' +myDate);

datetime myDateNew= myDT.addMinutes(30);
system.debug('@@@@@@@@@@@@@@@@' +myDateNew.format('h:mm a'));

 

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

downloadingdownloading

HI, 

thanks for your replay but this did not help me 

actuall iam using 

 

currentTime=string.valueof(datetime.now().format('HH:mm:ss'));   

 

to get the currenttime , i should be able to manipulate the above currentTime

 

how is this possible , 

 

 

ThankYou..!

 

 

SeAlVa_VFTabulatorSeAlVa_VFTabulator

Have you tried using an instance of Datetime and using its methods?

 

like addMinutes(X) ?

 

Take a look at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

 

Once you have the Datetime you want, you should be able to parse it as you want.

 

Regards.

kiranmutturukiranmutturu

try this

 

*********class*********

public class droptimeclass{

 


public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption(string.valueOf(system.now().time()),string.valueOf(system.now().time())));
options.add(new SelectOption(string.valueOf(system.now().time().addMinutes(-30)),string.valueOf(system.now().time().addMinutes(-30))));
options.add(new SelectOption(string.valueOf(system.now().time().addHours(-1)),string.valueOf(system.now().time().addHours(-1))));
options.add(new SelectOption(string.valueOf(system.now().time().addHours(-2)),string.valueOf(system.now().time().addHours(-2))));
return options;
}

 }

***********************************vfpage********************

<apex:page controller="droptimeclass">


<apex:form>
<apex:selectList id="chooseColor" size="1">
<apex:selectOptions value="{!items}"/>

</apex:selectList>
</apex:form>

</apex:page>