由于Bigquery数据库的查询响应,我不得不使用civil.Datetime。
如何从Golang的civil.Datetime中获取时间。时间日期?
类似的东西:
var date time.Time = civil.ToTime(myCivilTime)
我检查了民用时间文档:https://godoc.org/cloud.google.com/go/civil,并且有一个功能似乎可以满足我的要求。
func (d Date) In(loc *time.Location) time.Time
但是我不确定如何设置* time.Location参数。
答案 0 :(得分:2)
使用btnsubmit_Click
对您的应用程序有意义的任何内容。例如,
time.Location
输出:
package main
import (
"fmt"
"time"
"cloud.google.com/go/civil"
)
func main() {
now := time.Now().Round(0)
fmt.Println(now, " : time Now")
d := civil.DateTimeOf(now)
fmt.Println(d, " : civil DateTime")
t := d.In(time.UTC)
fmt.Println(t, " : time UTC")
t = d.In(time.Local)
fmt.Println(t, " : time Local")
pacific, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
fmt.Println(err)
return
}
t = d.In(pacific)
fmt.Println(t, " : time Pacific")
}
答案 1 :(得分:0)
除了@peterSO的答案外,如果您不想依赖于计算机的区域时间,还可以转换为 def main(args: Array[String]): Unit = {
val spark = SparkSession.builder().master("local[*]").
enableHiveSupport().getOrCreate()
spark.sqlContext.setConf("spark.sql.caseSensitive", "false")
import spark.implicits._
//hive table 存进行时会自动转小写
val hivetable = """{"deliverysystype":"dms","aaaa":"dms","orderid":"B0001-N103-000-005882-RL3AI2RWCP","storeid":"N103"}"""
val hiveDF = Seq(hivetable).toDF("msg")
val rdd = hiveDF.rdd.map(_.getString(0))
rdd.toDS().show(false)
val jsonDataDF = spark.read.json(rdd.toDS())
val jsonstr =
"""{"data":{"deliverySysType":"dms","orderId":"B0001-N103-000-005882-RL3AI2RWCP","storeId":"N103"},"accessKey":"f9d069861dfb1678","actionName":"candao.rider.getDeliveryInfo","timestamp":1571587522000,"ticket":"B0001.N127.FBDDS2.20191021000522156","serviceType":"delivery","sign":"fa0239c75e065cf43d0a4040665578ba" }"""
val jsonStrDF = Seq(jsonstr).toDF("msg")
jsonStrDF.show(false)
val structSeqSchme = StructType(Seq(StructField("data", jsonDataDF.schema, true),
StructField("accesskey", StringType, true),//这里应该 accessKey
StructField("actionName", StringType, true)))
//hive col name lower case, json data key capital and small letter,Take less than value
val mapOption = Map("accept_case_insensitive_properties" -> "true")//I'm not doing anything here, but I don't know how to set a value, right?
val newDF = jsonStrDF.withColumn("data_col", from_json(col("msg"), structSeqSchme, mapOption))
newDF.show(false)
newDF.printSchema()
newDF.select($"data_col.accessKey", $"data_col.actionName", $"data_col.data.*").show(false)
//+---------+----------------------------+----+---------------+-------+-------+
//|accessKey|actionName |aaaa|deliverysystype|orderid|storeid|
//+---------+----------------------------+----+---------------+-------+-------+
//|null |candao.rider.getDeliveryInfo|null|null |null |null |
//+---------+----------------------------+----+---------------+-------+-------+
}
,然后再次转换为string
:
time.Time