String2LongUtil
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的更多相关文章
随机推荐
- 05、解剖CEL文件各版本格式和读取方法(非R语言)
相比DAT文件,网络上更支持CEL级别的文件.CEL已经把DAT图像转换成数据了,而且CEL比DAT所占空间小得多.介绍一下CEL文件的格式,CEL文件有文本文件(TextCelFile,版本3).B ...
- IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\temp", 0); 报:异常来自 HRESULT:0x80040228
原因:未添加License. 解决办法:在窗体中添加LicenseControl即可.如下图,License图标运行时不会显示.
- vim学习(一)之简介、安装、配置
vim简介 Vim是从 vi 发展出来的一个文本编辑器,是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面. 简单的来说, vi 是老式的文字处理器,不过功能已经很齐全了,但是还是 ...
- springmvc中的参数接收
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...
- iPad和iPhone上的应用程序图标
iPad和iPhone上的应用程序图标 问:如何在iPad和iPhone使用我的应用程序包中的图标文件? 答:下面是处理文件的图标为iPhone专用的应用程序,iPad的专用应用程序,以及通用的应用程 ...
- 为了实现动态加载而编写的自己的ClassLoader
Copy备用 之前客户要求在不重启应用的前提下实现动态增加服务及交易,在网上查了很长时间也没发现类似的技术,最后研究了一下ClassLoader.因为项目是与Spring,一开始我和同事尝试替换源码的 ...
- Centos 7.5 双网卡内外网同时访问路由设置
说明:服务器有两张网卡分别是eth0.eth1,eth0配置内网IP:192.168.1.1/24,eth1配置外网IP:10.1.1.1/24:要求192.168.0.0/16网段走网卡eth0,网 ...
- java高并发核心要点|系列4|CPU内存指令重排序(Memory Reordering)
今天,我们来学习另一个重要的概念. CPU内存指令重排序(Memory Reordering) 什么叫重排序? 重排序的背景 我们知道现代CPU的主频越来越高,与cache的交互次数也越来越多.当CP ...
- 搭建团队协作办公wiki (confluence)
搭建环境 操作系统:centos7 数据库:mysql 一.准备工作 下载软件:atlassian-confluence-6.7.1-x64.bin wget https://downloads.at ...
- QT中获取选中的radioButton的两种方法
QT中要获取radioButton组中被选中的那个按钮,可以采用两种如下两种办法进行: 方法一:采用对象名称进行获取 代码: 1 QRadioButton* pbtn = qobject_cast&l ...