You need to sign in to do that
Don't have an account?

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
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.
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..!
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.
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>