I do not know what is wrong with code below -
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.textView1);
String dt;
Date cal = (Date) Calendar.getInstance().getTime();
dt = cal.toLocaleString();
tv.setText(dt.toString());
}
TextClock can display the current date and/or time as a formatted string. This view honors the 24-hour format system setting.
Consider using a TextClock as it will handle updates for you. For more info here is the documentation Docs . AnalogClock and DigitalClock can also be useful if your objective is just to display current time and date
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:format24Hour="MMM,yyyy\n\thh:mm"/>
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