I am using excel to get the data in java. I have given some date as yyyy-mm-dd. But when I am trying to get those values in the console using System.out.println(date). I am getting different date format as dd-mmm-yyyy. Whatever the date format I have given,in the console its printing only the dd-mmm-yyyy format.Any suggestion plz..
答案 0 :(得分:0)
If you use Date
object in System.out.println
, it will call toString()
method of Date
class and print the date in dd-mmm-yyyy
format (with time as well).
If you want to print Date
in any custom format then you need to use SimpleDateFormat
, e.g.:
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(format.format(date));
Here's the javadoc for SimpleDateFormat
class.