scala 时间格式转换(String、Long、Date)
1)scala 时间格式转换(String、Long、Date)
1、时间字符类型转Date类型
[java] view plain copy
import java.text.SimpleDateFormat
val time = "2017-12-18 00:01:56"
val newtime :Date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time)
println(newtime)
//output:Mon Dec 18 00:01:56 CST 2017
2、Long类型转字符类型
[java] view plain copy
val time:Long= //秒
val newtime :String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time*)
println(newtime)
//output:2017-12-21 15:01:07
3、时间字符类型转Long类型
[java] view plain copy
val time = "2017-12-18 00:01:56"
val newtime :Long= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time).getTime
println(newtime)
//output:1513526516000
2)scala 时间和时间戳互转
时间转换为时间戳:
import java.text.SimpleDateFormat
object test {
def main(args: Array[String]): Unit = {
val tm = "2017-08-01 16:44:32"
val a = tranTimeToLong(tm)
println(a)
}
def tranTimeToLong(tm:String) :Long={
val fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val dt = fm.parse(tm)
val aa = fm.format(dt)
val tim: Long = dt.getTime()
tim
}
}
时间戳转化为时间:
import java.text.SimpleDateFormat
import java.util.Date object test { def main(args: Array[String]): Unit = { val tm = ""
val a = tranTimeToString(tm)
println(a) } def tranTimeToString(tm:String) :String={
val fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val tim = fm.format(new Date(tm.toLong))
tim
}
}
scala 时间格式转换(String、Long、Date)的更多相关文章
- scala 时间,时间格式转换
scala 时间,时间格式转换 1.scala 时间格式转换(String.Long.Date) 1.1时间字符类型转Date类型 1.2Long类型转字符类型 1.3时间字符类型转Long类型 2. ...
- Kendo Web UI Grid里时间格式转换
我和大家分享一下我的kendo的学习心得.如果不好的地方多多包含或者给我留言请看图 kendo里时间格式如图Oder Date列里的格式.但是我们想把时间转换成中国人习惯的格式.如Shipped Da ...
- Java之格林威治时间格式转换成北京时间格式
Java之格林威治时间格式转换成北京时间格式 package com.mtons.mblog; import java.text.ParseException; import java.text.Si ...
- SQL Server日期时间格式转换字符串详解 (详询请加qq:2085920154)
在SQL Server数据库中,SQL Server日期时间格式转换字符串可以改变SQL Server日期和时间的格式,是每个SQL数据库用户都应该掌握的.本文我们主要就介绍一下SQL Server日 ...
- SQL Server日期时间格式转换字符串
在SQL Server数据库中,SQL Server日期时间格式转换字符串可以改变SQL Server日期和时间的格式,是每个SQL数据库用户都应该掌握的.本文我们主要就介绍一下SQL Server日 ...
- Sql日期时间格式转换;取年 月 日,函数:DateName()、DATEPART()
一.sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007 ...
- SQL Server日期时间格式转换字符串详解
本文我们主要介绍了SQL Server日期时间格式转换字符串的相关知识,并给出了大量实例对其各个参数进行对比说明,希望能够对您有所帮助. 在SQL Server数据库中,SQL Server日期时间格 ...
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- lua 特殊时间格式转换
[1]时间格式转换需求 工作中,因业务需要将时间格式进行转换.需求内容如下: 原格式:17:04:49.475 UTC Mon Mar 04 2019 转换格式:2019-03-04 17:04:4 ...
随机推荐
- SVN global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store */bin */ ...
- VS 2012 在 windows 8 中无法使用 Deubgger.Lunch() 对服务进行调试
找到了外文资料: Debugger.Launch() not displaying JIT debugger selection popup on Windows 8/8.1 If execu ...
- manbook pro和inode联网
macbook pro可以通过usb以太网转换器来实现有线联网. 1.下载inode 7 2.在终端中输入:sudo /library/StartupItems/iNodeAuthService/iN ...
- JavaScript浏览器检测之navigator 对象
一.使用客户端检测的原因 由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤. 虽然浏览器开发商在公共接口方面投入了很多精力,努力的去支持最常用的公共功能: 但在现实中 ...
- python中的装饰
在面向对象(OOP)的设计模式中,decorator被称为装饰模式.OOP的装饰模式需要通过继承和组合来实现,而Python除了能支持OOP的decorator外,直接从语法层次支持decorator ...
- Mybatis和Mysql的Json类型
Mysql5.7新增加了Json类型字段,但是目前Mybatis中并不支持 1.新建MybatisJsonTypeHandler.java import com.fasterxml.jackson.a ...
- MySQL 分库分表方案,总结的非常好!
前言 公司最近在搞服务分离,数据切分方面的东西,因为单张包裹表的数据量实在是太大,并且还在以每天60W的量增长. 之前了解过数据库的分库分表,读过几篇博文,但就只知道个模糊概念, 而且现在回想起来什么 ...
- 【React】使用 create-react-app 快速构建 React 开发环境
create-react-app 是来自于 Facebook,通过该命令我们无需配置就能快速构建 React 开发环境. create-react-app 自动创建的项目是基于 Webpack + E ...
- ethereumjs/ethereumjs-blockchain-1-简介和API
https://github.com/ethereumjs/ethereumjs-blockchain SYNOPSIS概要 A module to store and interact with b ...
- 日期字符串解析--SimpleDateFormat严格限制日期转换setLenient(false)
输入“33/12/2011”,用SimpleDateFormat parse()方法,转化为Date(2012,01,02).这样处理相当“33/12/2011”是正常输入,如果需要"33/ ...