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.
You are probably using java.sql.Date
. You want to be using java.util.Date
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With