I'm kind of stuck on date and time. I want my program to create the date like this "20121217". The first 4 letters are the year, the second 2 letters are the month and the last 2 are the day. year+month+day
The time is "112233" hour+minute+second
Thanks for your help!
To get both current date and time datetime. now() function of DateTime module is used. This function returns the current local date and time.
new Date() returns the current time, not the current date.
That's a formatting issue. Java uses java.util.Date
and java.text.DateFormat
and java.text.SimpleDateFormat
for those things.
DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd hhmmss");
dateFormatter.setLenient(false);
Date today = new Date();
String s = dateFormatter.format(today);
You can do something like this:
Calendar c = Calendar.getInstance();
String date = c.get(Calendar.YEAR) + c.get(Calendar.MONTH) + c.get(Calendar.DATE);
String time = c.get(Calendar.HOUR) + c.get(Calendar.MINUTE) + c.get(Calendar.SECOND);
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