public class String2LongUtil {
/**
* 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) {
KLog.d("进入stringToDate");
try {
SimpleDateFormat formatter = new SimpleDateFormat(formatType);
Date date;
date = formatter.parse(strTime);
return date;
} catch (Exception e) {
return null;
}
} /**
* String类型转换为long类型
* .............................
* strTime为要转换的String类型时间
* formatType时间格式
* formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
* strTime的时间格式和formatType的时间格式必须相同
*/
public static long stringToLong(String strTime, String formatType) {
KLog.d("进入stringToLong");
try {
//String类型转换为date类型
Date date = stringToDate(strTime, formatType);
KLog.d("调用stringToDate()获得的date:" + date);
if (date == null) {
return 0;
} else {
//date类型转成long类型
long Hour = date.getHours();
long Min = date.getMinutes();
long TimeLong = Hour * 60 * 60 * 1000 + Min * 60 * 1000;
KLog.d( "stringToLong()获得的Hour:" + Hour + " h");
KLog.d( "stringToLong()获得的Min:" + Min + " min");
KLog.d( "通过stringToLong()转换获得的long类型的时长 TimeLong:" + TimeLong + " ms");
return TimeLong;
}
} catch (Exception e) {
return 0;
}
}
}

String2LongUtil的更多相关文章

随机推荐

  1. PythonDay16

    第十六章模块 今日内容 自定义模块 time模块 datetime模块 rendom模块 自定义模块 # import 模块 例:import time# 导入的是time模块中所有的内容(变量,函数 ...

  2. 最近用到的postgresql 的一些操作

    通过Linux命令行连接:在本机上连接操作 第一步:su - postgres进入到这个:-bash-4.2$ 第二步:psql进入到数据库 切换数据库: 命令:\c dbname 进入到数据库中 查 ...

  3. docker安装教程-centos

    Docker 要求CentOS 系统的内核版本在3.10以上,查看本页面的前提条件来验证你的CentOS 版本是否支持Docker . 1.通过uname -r 命令查看你当前的内核版本 uname ...

  4. centos7配置mysql8.0主从复制

    注意:1.主库:10.1.131.75,从库:10.1.131.762.server-id必须是纯数字,并且主从两个server-id在局域网内要唯一. [主节点]vi /etc/my.cnf[mys ...

  5. java程序员面试宝典1

    1.在java中字符串只以Unicode一种形式存在(不选择任何特定的编码,直接使用他们在字符集中的编号,这是统一的唯一的方法) 2.在java中,是指在JVM中,在内存中,在你的代码里声明的每个ch ...

  6. Spring Boot自定义Redis缓存配置,保存value格式JSON字符串

    Spring Boot自定义Redis缓存,保存格式JSON字符串 部分内容转自 https://blog.csdn.net/caojidasabi/article/details/83059642 ...

  7. python语音提示

    #coding:utf8 import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") whi ...

  8. Linux练习例题(附答案)

    1.通过ps命令的两种选项形式查看进程信息 2.通过top命令查看进程 3.通过pgrep命令查看sshd服务的进程号 4.查看系统进程树 5.使dd if=/dev/zero of=/root/fi ...

  9. asp.net WebApi WebApiConfig.cs Web API 配置和服务

    public static void Register(HttpConfiguration config) { ............................... var jsonSett ...

  10. Azure云服务托管恶意软件

    微软Azure云服务被用于托管恶意软件,可控制多达90台电脑 BleepingComputer称,在早期报道中,5月份陆续出现了两起与Azure相关的恶意软件攻击事件: 1.自5月10日以来,Azur ...