Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "Date d = new Date();" return an error?

Tags:

date

android

time

This has probably been asked and answered a million times, but I can't seem to find a solution anywhere. Upon starting an activity in an android app, I want to display the current date and time. From what I understand the date part can be done simply with the following:

Date d = new Date();  
d.getTime();  
CharSequence s  = DateFormat.format("EEEE, MMMM d, yyyy", d.getTime());  

TextView date = (TextView)findViewById(R.id.dateText);  
date.setText(s);  

TextView time = (TextView)findViewById(R.id.timeText);  
time.setText(s);  

In eclipse it gives me an error and says that the constructor date is undefined. I chose the auto fix option and it added a 0 as a parameter in the Date constructor. This produced a date, but the date is Dec. 31, 1969. What am I missing here?

This is probably trivial, but I'm still new to this stuff.

Thanks in advance for any advice.

like image 998
Brandon Englert Avatar asked May 08 '11 21:05

Brandon Englert


1 Answers

You are probably using java.sql.Date. You want to be using java.util.Date.

like image 64
musaul Avatar answered Oct 20 '22 16:10

musaul