页面上读取timestamp对象的年月日和时分秒

后台java:

一个实体类对象,如MyData(String name,Timestamp time),传给页面前先将其转换成json字符串json_str,页面接收到数据后,通过

var json_obj = eval("(" + json_str + ")")

将json字符串转成json对象,接下来获取对象中的属性值:

json_obj.name;//获取name属性值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个可能的 Scala 工程代码示例,用于将 ods 库中的表抽取到 Hive 的 dwd 库中,同时格式化 timestamp 类型的数据: ```scala import java.text.SimpleDateFormat import java.util.{Calendar, TimeZone} import org.apache.spark.sql.SparkSession import org.apache.spark.sql.functions._ object OdsToDwd { def main(args: Array[String]): Unit = { val spark = SparkSession.builder() .appName("OdsToDwd") .enableHiveSupport() .getOrCreate() // 从 ods 库中读取表数据 val table1 = spark.table("ods.table1") val table2 = spark.table("ods.table2") val table3 = spark.table("ods.table3") val table4 = spark.table("ods.table4") val table5 = spark.table("ods.table5") val table6 = spark.table("ods.table6") val table7 = spark.table("ods.table7") val table8 = spark.table("ods.table8") val table9 = spark.table("ods.table9") val table10 = spark.table("ods.table10") val table11 = spark.table("ods.table11") // 格式化 timestamp 类型数据 val dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")) val formatTimestamp = udf((timestamp: String) => { if (timestamp == null) { null } else { val cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")) cal.setTimeInMillis(timestamp.toLong) cal.set(Calendar.MILLISECOND, 0) dateFormat.format(cal.getTime) } }) // 将数据写入 dwd 库中对应表 table1.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table1") table2.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table2") table3.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table3") table4.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table4") table5.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table5") table6.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table6") table7.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table7") table8.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table8") table9.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table9") table10.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table10") table11.selectExpr("*", "CAST(unix_timestamp(timestamp) AS STRING) AS timestamp_str") .withColumn("formatted_timestamp", formatTimestamp(col("timestamp_str"))) .drop("timestamp_str") .write.insertInto("dwd.table11") } } ``` 需要注意的是,这只是一个示例,实际代码可能需要根据具体情况进行修改和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值