How to get the current date and time in the JSP page

  • 2021-10-27 08:28:13
  • OfStack

1.


<SCRIPT LANGUAGE="JavaScript">
  var myDate = new Date();
  myDate.getYear();    // Get the current year (2 Bit )
  myDate.getFullYear();  // Get the full year (4 Bit ,1970-????)
  myDate.getMonth();   // Get the current month (0-11,0 Representative 1 Month )
  myDate.getDate();    // Get the current day (1-31)
  myDate.getDay();    // Get the current week X(0-6,0 On behalf of Sunday )
  myDate.getTime();    // Get the current time ( From 1970.1.1 Beginning milliseconds )
  myDate.getHours();   // Get the current number of hours (0-23)
  myDate.getMinutes();  // Get the current number of minutes (0-59)
  myDate.getSeconds();  // Gets the current number of seconds (0-59)
  myDate.getMilliseconds();  // Gets the current number of milliseconds (0-999)
  myDate.toLocaleDateString();  // Get the current date 
  var mytime=myDate.toLocaleTimeString();  // Get the current time 
  myDate.toLocaleString( );    // Get the date and time 

if (mytime<"23:30:00")
{
alert(mytime);
}
</SCRIPT>

2.


<% 
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

java.util.Date currentTime = new java.util.Date();// Get the current system time 

String str_date1 = formatter.format(currentTime); // Formatting Date Time  
String str_date2 = currentTime.toString(); // Will Date Type date and time to string form  
%>

Related articles: