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 

Date And Time

Hi ,

How would i get the curent date and Time and the browser,

I need to display these on the vf page these have to come from

the controller,

Could anyone help me with the sample code, how to achieve this in salesforce

 

Thank you.

Navatar_DbSupNavatar_DbSup

Hi,
Try the below code as reference:
///////////////////////// Controller ////////////////////////////

 

public class currentdatetime
{
public string currntdate{get;set;}
public string currenttime{get;set;}
public string url{get;set;}
public currentdatetime()
{
currntdate=string.valueof(system.now());
currenttime=string.valueof(system.now().format('hh:mm:ss'));
url=ApexPages.currentPage().getHeaders().get('Host');

system.debug('@@@@@@@@@@@Currentdate=========' +currntdate);
system.debug('@@@@@@@@@@@URL=========' +url);
}
}
/////////////////////////// VF Page ///////////////////////////////////
<apex:page controller="currentdatetime">
<apex:form >
CurrentDate:<apex:inputText value="{!currntdate}"/><br/>
CurrentTime:<apex:inputText value="{!currenttime}"/><br/>
BrowerUrl:<apex:inputText value="{!url}"/>
</apex:form>
</apex:page>

 

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