本文整理汇总了Python中obspy.UTCDateTime.format_seed方法的典型用法代码示例。如果您正苦于以下问题:Python UTCDateTime.format_seed方法的具体用法?Python UTCDateTime.format_seed怎么用?Python UTCDateTime.format_seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.UTCDateTime
的用法示例。
在下文中一共展示了UTCDateTime.format_seed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_formatSEED
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import format_seed [as 别名]
def test_formatSEED(self):
"""
Tests format_seed method
"""
# 1
dt = UTCDateTime("2010-01-01")
self.assertEqual(dt.format_seed(compact=True), "2010,001")
# 2
dt = UTCDateTime("2010-01-01T00:00:00.000000")
self.assertEqual(dt.format_seed(compact=True), "2010,001")
# 3
dt = UTCDateTime("2010-01-01T12:00:00")
self.assertEqual(dt.format_seed(compact=True), "2010,001,12")
# 4
dt = UTCDateTime("2010-01-01T12:34:00")
self.assertEqual(dt.format_seed(compact=True), "2010,001,12:34")
# 5
dt = UTCDateTime("2010-01-01T12:34:56")
self.assertEqual(dt.format_seed(compact=True), "2010,001,12:34:56")
# 6
dt = UTCDateTime("2010-01-01T12:34:56.123456")
self.assertEqual(dt.format_seed(compact=True),
"2010,001,12:34:56.1234")
# 7 - explicit disabling compact flag still results into compact date
# if no time information is given
dt = UTCDateTime("2010-01-01")
self.assertEqual(dt.format_seed(compact=False), "2010,001")
示例2: datetime_2_string
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import format_seed [as 别名]
def datetime_2_string(dt, compact=False):
"""
Generates a valid SEED time string from a UTCDateTime object.
"""
if isinstance(dt, UTCDateTime):
return dt.format_seed(compact)
elif isinstance(dt, (str, native_str)):
dt = dt.strip()
if not dt:
return ""
try:
dt = UTCDateTime(dt)
return dt.format_seed(compact)
except Exception:
raise Exception("Invalid datetime %s: %s" % (type(dt), str(dt)))