Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

TIME

anybody can provide the codes to get current time and date?
0
kirov
Asked:
kirov
1 Solution
 
thanassisCommented:
you ca use the class Date as follows:

<%java.util.Date d = new Date();%>
<%=d%>
0
 
fargoCommented:
Hii,

java.text.SimpleDateFormat dFormat=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String today = dFormat.format(new java.util.Date());

Use any format u want to extract the date and time.
Hope this helps
happy working
fargo

0
 
Binary1Commented:
java.util.GregorianCalendar can be used if you need to access the specific date/time fields, Month, day, hour, etc.
0
 
r_a_j_e_s_hCommented:
<%@ page contentType="text/html" %>

<%@ page language="java" import="java.util.*" %>

<%
Calendar cal = new GregorianCalendar();
          // Get the components of the date
int era = cal.get(Calendar.ERA);
         // 0=BC, 1=AD
int year = cal.get(Calendar.YEAR);  
         // 2002
int month = cal.get(Calendar.MONTH);
          // 0=Jan, 1=Feb, ...
int day = cal.get(Calendar.DAY_OF_MONTH);  
          // 1...
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
         // 1=Sunday, 2=Monday, ...

java.util.Date d1=new Date(year,month,day);
out.println(d1);
%>
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to thanassis

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now