获取日期类型对象,格式为java [英] Get Date type object in format in java
问题描述
Java.util.Date
或 Calender
实例或使用 GregorianCalendar
实例。 使用类' SimpleDateFormat
'我们可以 parse()
或 format()
函数我们的日期
或 String
。
正如我们所知,使用 parse()
或 format()
函数,我们只得到一个 String
的输出。
在java中有没有可用的选项来获取日期
特定格式的实例,如yyyy-MM-dd或任何其他格式,但最终输出应为日期
类型使用这种格式?
Date 根本没有格式。这只是时间的表示,因为标准基础时间被称为时代,即1970年1月1日,00:00:00 GMT 。
您只能使用 SimpleDateFormat
。
另外,<$ SDF的c $ c> parse()方法解析Date对象的String表示形式。 format()
是给出Date对象格式化的String表示形式的方法。
As we know we can get date using Java.util.Date
or Calender
instance or by using GregorianCalendar
instance .
Using class 'SimpleDateFormat
' we can parse()
or format()
function our Date
or String
.
As we know using parse()
or format()
function we get output as a String
only.
Is there any option available in java to get Date
instance in particular format like 'yyyy-MM-dd' or any other format, but final output should be of Date
type with this format ?
Date doesn't have a format at all. It is just the representation of time since the standard base time known as The Epoch, namely January 1, 1970, 00:00:00 GMT.
You can only get a String representation of the Date in the format required using the SimpleDateFormat
.
Also, parse()
method of SDF parses the String representation of the Date to a Date object. format()
is the method which gives the formatted String representation of the Date object.
这篇关于获取日期类型对象,格式为java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!