import java.util.*;
import java.text.*;
class DemoDate
{
public static void main(String[] args)
{
Date date=new Date();
SimpleDateFormat sdf;
// sdf=new SimpleDateFormat("hh:mm:ss");
//System.out.println(sdf.format(date));
// sdf=new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");
//System.out.println(sdf.format(date));
sdf=new SimpleDateFormat("E MMM dd yyyy hh:mm:ss");
System.out.println(sdf.format(date));
}
}

i am getting current date and time but i want to catch that time (as a login time 4 a person)in my jsp whenever i refresh i am getting current system time .Suppose i logged in at 2:00 that time should be there ...................plz help me

The variable date is an object of class Date not a string constant. The date object will give you the current date when ever you call on it. You should try to save the time stamp to a string variable. I like to use the Calender class since a lot of the functionalities of the Date class has been deprecated.

import java.util.*;
import java.text.*;


class DemoDate

{
    public static void main(String[] args)
    {
        Calendar cal = new GregorianCalendar();

        String login = cal.getTime().toString();
    }
}

The string login will contain the time stamp.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.