I’m quite new to visualforce/apex programming and kinda stuck in parsing current time and time functions in apex.
Basically I’m trying to figure out if the current time is within my given time range.
How do I write this in apex language?
public String isWorkhours;
public String getIsWorkhours() {
Datetime current_time = *(get current time)*
Datetime start_time = *(7:00 am)*
Datetime end_time = *(7:00 pm)*
if ((current_time >= start_time) && (current_time <= end_time)) {
isWorkhours= 'yes';
} else {
isWorkhours= 'no';
}
return isWorkhours;
}
First of all – check if you can use Business Hours (standard object) to configure SF instead of writing similar functionality manually. Just check your online help for these.
Example of comparison of 2 datetime objects: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_businesshours.htm
Secondly – read the reference of Time class. Something like this?