返回日期类型,格式为java [英] return date type with format in java

查看:299
本文介绍了返回日期类型,格式为java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现变量的get方法具有类型Date。
但是当返回时,我想以格式yyyy / MM / dd返回它,并且必须是日期类型。

I'm trying implement get method for variable has type "Date". But when return, I want to return it with format "yyyy/MM/dd" and MUST be Date type.

示例:原始日期:2018 / 01 / 01T15:00.00.000 + 0000

Example: original date: 2018/01/01T15:00.00.000+0000

我要返回:2018-01-01并且必须是日期,而不是字符串

I want return: 2018-01-01 and MUST be date, not string

在这种情况下你能帮助我吗?

Can you help me in this case ?

推荐答案

A 日期基本上存储为自纪元(1970年1月1日)以来的毫秒数。它可以以各种方式格式化为 String (例如,使用 SimpleDateFormat ),但它永远不会存储为字符串。所以,你所要求的是不可能的,没有任何意义。

A Date is basically stored as a number of milliseconds since the epoch (1/1/1970). It can be formatted into a String in various ways (e.g. with SimpleDateFormat), but it is never stored as a String. So, what you're asking for is impossible and makes no sense.

这篇关于返回日期类型,格式为java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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