// date类型转换为String类型
// formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
// data Date类型的时间
public static String dateToString(Date data, String formatType) {
return new SimpleDateFormat(formatType).format(data);
} // long类型转换为String类型
// currentTime要转换的long类型的时间
// formatType要转换的string类型的时间格式
public static String longToString(long currentTime, String formatType)
throws ParseException {
Date date = longToDate(currentTime, formatType); // long类型转成Date类型
String strTime = dateToString(date, formatType); // date类型转成String
return strTime;
} // string类型转换为date类型
// strTime要转换的string类型的时间,formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日
// HH时mm分ss秒,
// strTime的时间格式必须要与formatType的时间格式相同
public static Date stringToDate(String strTime, String formatType)
throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat(formatType);
Date date = null;
date = formatter.parse(strTime);
return date;
} // long转换为Date类型
// currentTime要转换的long类型的时间
// formatType要转换的时间格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
public static Date longToDate(long currentTime, String formatType)
throws ParseException {
Date dateOld = new Date(currentTime); // 根据long类型的毫秒数生命一个date类型的时间
String sDateTime = dateToString(dateOld, formatType); // 把date类型的时间转换为string
Date date = stringToDate(sDateTime, formatType); // 把String类型转换为Date类型
return date;
} // string类型转换为long类型
// strTime要转换的String类型的时间
// formatType时间格式
// strTime的时间格式和formatType的时间格式必须相同
public static long stringToLong(String strTime, String formatType)
throws ParseException {
Date date = stringToDate(strTime, formatType); // String类型转成date类型
if (date == null) {
return 0;
} else {
long currentTime = dateToLong(date); // date类型转成long类型
return currentTime;
}
} // date类型转换为long类型
// date要转换的date类型的时间
public static long dateToLong(Date date) {
return date.getTime();
}

Data、String、Long三种日期类型之间的相互转换的更多相关文章

  1. java Data、String、Long三种日期类型之间的相互转换

    java Data.String.Long三种日期类型之间的相互转换      // date类型转换为String类型   // formatType格式为yyyy-MM-dd HH:mm:ss// ...

  2. Android:Date、String、Long三种日期类型之间的相互转换

    源地址:http://blog.csdn.net/wangyanguiyiyang date类型转换为String类型: // formatType格式为yyyy-MM-dd HH:mm:ss//yy ...

  3. 关于MySQL中的三种日期类型

    Mysql中我们经常用来存储日期的数据类型有三种:Date.Datetime.Timestamp. Date数据类型用来存储没有时间的日期.Mysql获取和显示这个类型的格式为"YYYY-M ...

  4. Java的三种日期工具 Date Calendar SimpleDateFormat

    三种日期工具 配合下面的案例可以更加深度的了解 Date 需要导包java.util.Date Date d = new Date(); //两种都是获取到现在时间的时间戳 long t1 = d.g ...

  5. 固本培元之三:Convert、运算符、流程控制语句、ref/out/in三种参数类型

    一.Convert类常用的类型转换方法Convert.ToInt32() 转换为整型(int)Convert.ToChar() 转换为字符型(char)Convert.ToString() 转换为字符 ...

  6. DB2中字符、数字和日期类型之间的转换

    DB2中字符.数字和日期类型之间的转换 一般我们在使用DB2或Oracle的过程中,经常会在数字<->字符<->日期三种类 型之间做转换,那么在DB2和Oracle中,他们分别 ...

  7. Delphi中定义了四种布尔类型:Boolean,ByteBool,WordBool和LongBool。后面三种布尔类型是为了与其他语言兼容而引入的

    bool是LongBool类型. Delphi中定义了四种布尔类型:Boolean,ByteBool,WordBool和LongBool.后面三种布尔类型是为了与其他语言兼容而引入的,一般情况下建议使 ...

  8. xhtml三种元素类型

    xhtml三种元素类型:块级元素/内联元素/可变元素 块级元素:独占一行.可自定义自己的宽度和高度.作为其他元素的容器,可容纳其他内联元素和块级元素,喻做一个盒子.内联元素:始终以行内逐个显示.不能设 ...

  9. sql server 性能调优之 资源等待内存瓶颈的三种等待类型

    一.概述 这篇介绍Stolen内存相关的主要三种等待类型以及对应的waittype编号,CMEMTHREAD(0x00B9),SOS_RESERVEDMEMBLOCKLIST(0x007B),RESO ...

随机推荐

  1. RedHat安装yum+配置国内yum源

      新安装了redhat6.5安装后,登录系统,使用yum update 更新系统.提示: This system is not registered to Red Hat Subscription ...

  2. ACM解题之快速输出杨辉三角形(前68行)

    题意: 本题要求计算并输出杨辉三角形的前 68 行. Time Limit:1000MS Memory Limit:65536K 解题: 为了能在规定时间准确输出杨辉三角形的前68行,这里我用了精准的 ...

  3. Python基础(17)_面向对象程序设计(抽象类、继承原理、封装、多态,绑定方法)

    一.抽象类 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化 1.在python中实现抽象类 import abc #利用abc模块实现抽象类 class All_file(metacl ...

  4. Linux基础系列:常用命令(4)_系统监控

    1. 系统监视和进程控制工具—top和free 1) top命令的功能:top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. 2) ...

  5. 流量分析系统---kafka集群部署

    1.集群部署的基本流程 Storm上游数据源之Kakfa 下载安装包.解压安装包.修改配置文件.分发安装包.启动集群 2.基础环境准备 安装前的准备工作(zk集群已经部署完毕)  关闭防火墙 chk ...

  6. SQL Server 存储过程 分页查询

    Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...

  7. Python学习进程(13)文件与IO

        本节介绍基本的IO函数和文件的读写操作.     (1)读取键盘输入: Python用于读取键盘输入的函数有两个:raw_input与input. 1)raw_input函数 从标准输入读取一 ...

  8. vscode使用vue中的v-for提示错误

    "vetur.validation.template": false 在设置里面把vetur.validation.template改为false 文件→首选项→设置 搜索vetu ...

  9. 【HackerRank】 Chocolate Feast

    Little Bob loves chocolates, and goes to the store with $N money in his pocket. The price of each ch ...

  10. id和NSObject *和instanceType的区别与联系

    id 被成为万能指针,也就是可以指向任何对象. NSObject * 本身就是定义指向NSObject类型的指针. 那么这两者有什么区别吗? 这两者都是既可以作为返回值,又可以作为变量修饰.而其主要区 ...