0

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

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Rayhan Muktader
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.