使用 +1000 个值转换日期 [英] Convert Date with +1000 values

查看:60
本文介绍了使用 +1000 个值转换日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的日期:2018-04-30T23:22:05+1000 并想转换为 Date 对象

let formatter = DateFormatter()formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss:Z"//z, zz 还是 nil让 ss = formatter.date(来自:2018-04-30T23:22:05+1000")print("VAL : \(ss)")//始终为零

+1000 值的正确格式是什么?

此外,我必须添加什么语言环境才能获得确切日期?

解决方案

使用你的日期格式

I have a date like this : 2018-04-30T23:22:05+1000 and want to convert in to Date Object

let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss:Z" // z, zz also still nil
let ss = formatter.date(from: "2018-04-30T23:22:05+1000")
print("VAL : \(ss)") // nil always

What is the correct format for +1000 values?

Also what locale i have to add to get exact date?

解决方案

use your dateformat as zone - The long specific non-location format. Where that is unavailable, falls back to the long localized GMT format ("0000").

                             //2018-04-30T23:22:05+1000
       formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" 

instead of

       formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss:Z" // z, zz also still nil

full answer

    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" 
    let ss = formatter.date(from: "2018-04-30T23:22:05+1000")
    print("VAL : \(ss)") // nil always

这篇关于使用 +1000 个值转换日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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