Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What kind of different date formats are allowed for the Date constructor with the string parameter?

0
Posted

What kind of different date formats are allowed for the Date constructor with the string parameter?

0

• A. That constructor is now deprecated, so you should not use it. Instead, you should convert a date/time String into a Date like this: // don’t forget to set the default TZ if needed. DateFormat HHmm = new SimpleDateFormat( “HH:mm” ); HHmm.setTimeZone( TimeZone.getDefault() ); Date lunch = HHmm.parse( “12:30” ); System.out.println( lunch ); The above code would result in (when in the MST timezone), Thu Jan 01 12:30:00 MST 1970 To parse other date and time fields, refer to the SimpleDateFormat documentation.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.