使用datetime.strptime解析GST时区

时间:2019-07-03 14:24:26

标签: python datetime

我正在尝试将2. Unhandled clojure.lang.Compiler$CompilerException Error compiling src/dipping_feet/gui.clj at (1:1) #:clojure.error{:phase :macro-syntax-check, :line 1, :column 1, :source 1. Caused by clojure.lang.ExceptionInfo Call to clojure.core/ns did not conform to spec. #:clojure.spec.alpha{:problems [{:path [], :reason "Extra input", :pred (clojure.spec.alpha/cat :docstring (clojure.spec.alpha/? clojure.core/string?) :attr-map (clojure.spec.alpha/? clojure.core/map?) :ns-clauses :clojure.core.specs.alpha/ns-clauses), :val ((:gen-class :name joy.gui.DynaFrame :extends javax.swing.JFrame :implements [clojure.lang.IMeta] :prefix df- :state state :init init :constructors {[String] [String], [] [String]} :methods [[display [java.awt.Container] void] [version [] String]]) (:import (javax.swing JFrame JPanel JComponent) (java.awt BorderLayout Container))), :via [:clojure.core.specs.alpha/ns-form], :in [1]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x3b982314 "clojure.spec.alpha$regex_spec_impl$reify__2509@3b982314"], :value (joy.gui (:gen-class :name joy.gui.DynaFrame :extends javax.swing.JFrame :implements [clojure.lang.IMeta] :prefix df- :state state :init init :constructors {[String] [String], [] [String]} :methods [[display [java.awt.Container] void] [version [] String]]) (:import (javax.swing JFrame JPanel JComponent) (java.awt BorderLayout Container))), :args (joy.gui (:gen-class :name joy.gui.DynaFrame :extends javax.swing.JFrame :implements [clojure.lang.IMeta] :prefix df- :state state :init init :constructors {[String] [String], [] [String]} :methods [[display [java.awt.Container] void] [version [] String]]) (:import (javax.swing JFrame JPanel JComponent) (java.awt BorderLayout Container)))} 解析为str对象。但是,由于时区为datetime.datetime,因此我无法实现。

GST

我该如何解决?

1 个答案:

答案 0 :(得分:1)

有两种处理方法:-

  1. 将字符串中的GST替换为UTC

  2. 将字符串中的GST替换为UTC,并进行适当的时间转换(将UTC时间减少4小时,因为GST时间比UTC +4小时)。

方法1:-

version of MessageKit : 2.0.0
version of iOS : 12
version of Swift : 4.2

方法2:-

s_dt = 'Mon Jul 01 17:17:37 GST'.replace("GST", "UTC")

datetime.datetime.strptime(s_dt, '%a %b %d %H:%M:%S %Z')