获取日期类型对象,格式为java [英] Get Date type object in format in java

查看:111
本文介绍了获取日期类型对象,格式为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆