如何使用ThreeTenABP将java.util.Date更改为ISO String

时间:2018-06-01 09:00:23

标签: java android datetime iso8601 threetenbp

我正在使用ThreeTenABP转换Android的日期时间。 我的问题是如何通过ThreeTenABP将java.util.Date更改为ISO字符串(格式为2018-05-24T02:33:10.062Z)?

3 个答案:

答案 0 :(得分:3)

ThreetenABP-solution可能如下所示:

java.util.Date d = ...;
org.threeten.bp.Instant instant = org.threeten.bp.DateTimeUtils.toInstant(d);
String iso = instant.toString();

如果您希望更好地控制格式,那么您可以将广告转换为ZonedDateTime(或更好to an OffsetDateTime)并使用专用的DateTimeFormatter

答案 1 :(得分:1)

我不知道android,但如果vue.runtime.esm.js:588 [Vue warn]: Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] Do not mutate vuex store state outside mutation handlers." (found in <Root>) warn @ vue.runtime.esm.js:588 logError @ vue.runtime.esm.js:1732 globalHandleError @ vue.runtime.esm.js:1727 handleError @ vue.runtime.esm.js:1716 run @ vue.runtime.esm.js:3230 update @ vue.runtime.esm.js:3202 notify @ vue.runtime.esm.js:694 mutator @ vue.runtime.esm.js:841 (anonymous) @ main.js:91 fireGtmPixels @ main.js:83 (anonymous) @ main.js:69 Promise.then (async) (anonymous) @ main.js:68 Promise.then (async) (anonymous) @ main.js:64 ./client/main.js @ cmp:263 __webpack_require__ @ cmp:62 (anonymous) @ cmp:179 (anonymous) @ cmp:182 vue.runtime.esm.js:1736 Error: [vuex] Do not mutate vuex store state outside mutation handlers. at assert (vuex.esm.js:105) at Vue.store._vm.$watch.deep (vuex.esm.js:754) at Watcher.run (vue.runtime.esm.js:3228) at Watcher.update (vue.runtime.esm.js:3202) at Dep.notify (vue.runtime.esm.js:694) at Array.mutator (vue.runtime.esm.js:841) at eval (main.js:91) at new Promise (<anonymous>) at fireGtmPixels (main.js:83) at eval (main.js:69) logError @ vue.runtime.esm.js:1736 globalHandleError @ vue.runtime.esm.js:1727 handleError @ vue.runtime.esm.js:1716 run @ vue.runtime.esm.js:3230 update @ vue.runtime.esm.js:3202 notify @ vue.runtime.esm.js:694 mutator @ vue.runtime.esm.js:841 (anonymous) @ main.js:91 fireGtmPixels @ main.js:83 (anonymous) @ main.js:69 Promise.then (async) (anonymous) @ main.js:68 Promise.then (async) (anonymous) @ main.js:64 ./client/main.js @ cmp:263 __webpack_require__ @ cmp:62 (anonymous) @ cmp:179 (anonymous) @ cmp:182 vue.runtime.esm.js:588 [Vue warn]: Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] Do not mutate vuex store state outside mutation handlers." (found in <Root>) warn @ vue.runtime.esm.js:588 logError @ vue.runtime.esm.js:1732 globalHandleError @ vue.runtime.esm.js:1727 handleError @ vue.runtime.esm.js:1716 run @ vue.runtime.esm.js:3230 update @ vue.runtime.esm.js:3202 notify @ vue.runtime.esm.js:694 mutator @ vue.runtime.esm.js:841 (anonymous) @ main.js:94 fireGtmPixels @ main.js:83 (anonymous) @ main.js:69 Promise.then (async) (anonymous) @ main.js:68 Promise.then (async) (anonymous) @ main.js:64 ./client/main.js @ cmp:263 __webpack_require__ @ cmp:62 (anonymous) @ cmp:179 (anonymous) @ cmp:182 vue.runtime.esm.js:1736 Error: [vuex] Do not mutate vuex store state outside mutation handlers. at assert (vuex.esm.js:105) at Vue.store._vm.$watch.deep (vuex.esm.js:754) at Watcher.run (vue.runtime.esm.js:3228) at Watcher.update (vue.runtime.esm.js:3202) at Dep.notify (vue.runtime.esm.js:694) at Array.mutator (vue.runtime.esm.js:841) at eval (main.js:94) at new Promise (<anonymous>) at fireGtmPixels (main.js:83) at eval (main.js:69) 可用,你可以这样做:

java.text.SimpleDateFormat

答案 2 :(得分:0)

表达:

new Date().toInstant().toString()

产生

2019-12-31T06:32:37.997Z