时间字符串与当前时间比較
public static String getCurrentTime(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
/*时间比大小*/
public static int timeCompare(String t1,String t2){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1=Calendar.getInstance();
Calendar c2=Calendar.getInstance();
try {
c1.setTime(formatter.parse(t1));
c2.setTime(formatter.parse(t2));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int result=c1.compareTo(c2);
return result;
}
// public static void main(String[] args) {
// String coupon_valid_end = "3004-03-26 13:31:40";
//String currenttime = getCurrentTime();
// int flagnum = timeCompare(coupon_valid_end, currenttime);
// System.out.println(flagnum);
//}
转载于:https://www.cnblogs.com/yutingliuyl/p/6756210.html
时间字符串与当前时间比較相关推荐
- pandas使用to_datetime函数将时间字符串转化为时间对象、使用dt.tz_localize为转化后的时间对象添加时区信息(timezone)
pandas使用to_datetime函数将时间字符串转化为时间对象.使用dt.tz_localize为转化后的时间对象添加时区信息(timezone) 目录 pandas使用to_datetime函 ...
- pandas使用to_datetime函数将时间字符串转化为时间对象、其中月份内容为字母而非数字(例如,“January 2, 2022“)
pandas使用to_datetime函数将时间字符串转化为时间对象.其中月份内容为字母而非数字(例如,"January 2, 2022") 目录 pandas使用to_datet ...
- java 字符串转utc时间_JAVA 本地时间字符串转UTC时间字符串
本来想偷懒百度一个时间字符串转UTC的代码,但发现没有一个能用,写得还复杂得要死,没办法还是自己撸一个. /** * UTC时间字符串转本地时间字符串 * 我的本地getDateTimeInstanc ...
- 时间字符串string转换为时间格式nsdate
废话不多说直接贴代码: 一.字符串转时间格式 //字符串转换为日期// 实例化NSDateFormatterNSDateFormatter *inputFormatter= [[NSDateForma ...
- python 当前时间字符串,Python常用时间操作总结【取得当前时间、时间函数、应用等】...
本文实例讲述了Python常用时间操作.分享给大家供大家参考,具体如下: 我们先导入必须用到的一个module >>> import time 设置一个时间的格式,下面会用到 > ...
- linux时间字符串转正常时间
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- js 把字符串格式化成时间
一 需求 js里面的Date.parse() 方法接收字符串,返回一个时间,但是接收的字符串格式缺不能指定,这很蛋疼,这样就有了浏览器差异,所以需要一个可以指定字符串格式的方法,将时间字符串转化为时间 ...
- golang时间字符串和时间戳转换
1. 获取当前时间字符串和时间戳 package mainimport ("fmt""time" )func main() {now := time.Now() ...
- java 字符串转utc时间_Java中转UTC时间字符串(含有T Z)为local时间
在Java中我们需要转换相应格式的字符串,很多时候我们想到用SimpleDateFormat类来解析.但是最近我在调用一个第三方的接口时返回的 JSON字符串中有个expires字段的值是2014-0 ...
最新文章
- mongo 脚本对应的C#实现方式(待整理)
- ASP.NET存取图片到数据库
- react中js文件中写html,javascript – 使用静态HTML与React
- Py之pycurl:Python 库之pycurl的简介、安装、使用方法之详细攻略
- Node.js基础知识普及
- SDUTOJ3468_广度优先搜索练习之神奇的电梯(BFS + 用vector建图)
- 父组件传递值给子组件(一)
- Java 14 有哪些新特性?
- 复制文字到剪贴板的几种方法
- 教程丨一文了解如何在OpenSea上创建自己的NFT商店
- Unity 3D学习(基础篇)——C#基础入门
- c 语言中析构函数,详解C++编程中的析构函数
- 翻译文章“AST 模块:用 Python 修改 Python 代码”---!!注意ironpathyon未实现此功能...
- 为什么要使用ELK-----EKL的原理 ---以及ELK的配置 详细! 小白都能懂
- thread ‘main‘ panicked at ‘called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound
- C语言100题练习计划 32——猜数字游戏
- 网络流中最大流和最小割算法
- 构造二叉树-前序遍历
- 总结一些常见的国际标准化组织
- TCP系列43—拥塞控制—6、Congestion Window Validation(CWV)