simpledateformat

Java中日期格式转换

拟墨画扇 提交于 2020-01-04 03:14:24
java日期格式大全 format SimpleDateFormat Java中日期格式转换 /** * 字符串转换为java.util.Date * 支持格式为 yyyy.MM.dd G 'at' hh:mm:ss z 如 '2002-1-1 AD at 22:10:59 PSD' * yy/MM/dd HH:mm:ss 如 '2002/1/1 17:55:00' * yy/MM/dd HH:mm:ss pm 如 '2002/1/1 17:55:00 pm' * yy-MM-dd HH:mm:ss 如 '2002-1-1 17:55:00' * yy-MM-dd HH:mm:ss am 如 '2002-1-1 17:55:00 am' * @param time String 字符串 * @return Date 日期 */ public static Date stringToDate(String time){ SimpleDateFormat formatter; int tempPos=time.indexOf("AD") ; time=time.trim() ; formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z"); if(tempPos>-1){ time=time.substring(0

Java 日期计算

断了今生、忘了曾经 提交于 2020-01-04 02:18:58
Java 计算日期加、减一天 方法一 SimpleDateFormat newdate = new SimpleDateFormat("HH:mm:ss");//设置时间格式 String time1 = newdate.format(new Date());//获取当前系统时间 String time2= "00:00:00";//大于时间 String time3= "15:59:59";//小于时间 Date dt1 = newdate.parse(time1); Date dt2 = newdate.parse(time2); Date dt3 = newdate.parse(time3); if(dt2.getTime() < dt1.getTime() || dt1.getTime() <dt3.getTime()) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); Calendar rightNow = Calendar.getInstance(); rightNow.add(Calendar.DATE,-2);//当前时间减2天 Date dt8 = rightNow.getTime(); newRQ = sdf.format(dt8);

日期格式化跨年bug,是否与你不期而遇?

a 夏天 提交于 2020-01-04 00:27:30
public class DateFormatBug { public static void main(String[] args) throws ParseException { // 示例一 printBugDate(); } private static void printBugDate() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); Date date = sdf.parse("2020-1-1 13:12:12"); System.out.println(date); String dateStr = sdf.format(date); System.out.println(dateStr); } } 打印日志为: Sun Dec 29 13:12:12 CST 2019 2020-12-29 13:12:12 示例二,延伸示例: private static void printBugDateExtend() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); Date date = sdf

Quartz入门

社会主义新天地 提交于 2020-01-03 23:07:29
文章目录 1、Quartz简介及应用场景 Quartz介绍 2、Quartz简单触发器 SimpleTrigger介绍 图解quartz工作流程 准备 案例 语法 3、Quartz表达式触发器CronTirgger介绍 4、Quartz中参数传递 5、Spring task **Vs** Quartz Spring task Quarz 1、Quartz简介及应用场景 Quartz介绍 任务调度框架“Quartz”是OpenSymphony开源组织在Job scheduling领域又一个开源项目,是完全由java开发的一个开源的任务日程管理系统, “任务进度管理器”就是一个在预先确定(被纳入日程)的时间到达时,负责执行(或者通知)其他软件组件的系统。 简单来说就是实现“计划(或定时)任务”的系统,例如:订单下单后未付款,15分钟后自动撤消订单,并自动解锁锁定的商品 2、Quartz简单触发器 SimpleTrigger介绍 触发器用来告诉调度程序作业什么时候触发。框架提供了5种触发器类型,但两个最常用的SimpleTrigger和CronTrigger。 五种类型的Trigger(定时器) SimpleTrigger,CronTirgger,DateIntervalTrigger,NthIncludedDayTrigger和Calendar类( org.quartz

SimpleDateFormat parse is one hour out (using RFC 1123, GMT in summer)

心不动则不痛 提交于 2020-01-02 08:09:40
问题 I am using SimpleDateFormat with RFC 1123 to format dates, and to parse dates. However, parse(format(date)) is sometimes one hour different from the original date. The code below: public static void main(String[] args) throws ParseException { String RFC1123_DATE_PATTERN = "EEE, dd MMM yyyy HH:mm:ss zzz"; SimpleDateFormat dateFormat = new SimpleDateFormat(RFC1123_DATE_PATTERN); Date date = new Date(1000); String str = dateFormat.format(date); Date date2 = dateFormat.parse(str); System.out

Format a datetime string to time only

两盒软妹~` 提交于 2020-01-02 05:43:10
问题 I'm retrieving a datetime from a SQLite DB which comes out in the format... 2011-01-24 02:45:00 In C# I can simply use DateTime.Parse("2011-01-24 02:45:00").ToString("HH:mm") in order to get the string 02:45 Is their a way I can I do this in Android/Java? My code in my Android app looks like this... // dateStr below is logging as correctly being yyyy-MM-dd HH:mm:ss format String dateStr = cursor.getString(cursor.getColumnIndex("start_time")); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm

Generating all days between 2 given dates in Java [duplicate]

时间秒杀一切 提交于 2020-01-02 02:33:08
问题 This question already has answers here : how to get a list of dates between two dates in java (22 answers) Closed 2 years ago . I'm trying to get an array of Dates, while my input is a 'from'/'to' structure. So my input is: String date1 = "2014-01-01"; String date2 = "2014-05-01"; My output should be an Arraylist with all dates between date1 and date2. I've already looked for this, but I could only find questions about the difference between 2 dates: SimpleDateFormat myFormat = new

Generating all days between 2 given dates in Java [duplicate]

空扰寡人 提交于 2020-01-02 02:33:06
问题 This question already has answers here : how to get a list of dates between two dates in java (22 answers) Closed 2 years ago . I'm trying to get an array of Dates, while my input is a 'from'/'to' structure. So my input is: String date1 = "2014-01-01"; String date2 = "2014-05-01"; My output should be an Arraylist with all dates between date1 and date2. I've already looked for this, but I could only find questions about the difference between 2 dates: SimpleDateFormat myFormat = new

Getting pattern string from java SimpleDateFormat

大憨熊 提交于 2020-01-01 23:17:07
问题 I have a SimpleDateFormat object that I retrieve from some internationalization utilities. Parsing dates is all fine and good, but I would like to be able show a formatting hint to my users like "MM/dd/yyyy". Is there a way to get the formatting pattern from a SimpleDateFormat object? 回答1: SimpleDateFormat.toPattern() Returns a pattern string describing this date format. 回答2: If you just need to get a pattern string for the given locale, the following worked for me: /* Obtain the time format

Getting pattern string from java SimpleDateFormat

自作多情 提交于 2020-01-01 23:16:52
问题 I have a SimpleDateFormat object that I retrieve from some internationalization utilities. Parsing dates is all fine and good, but I would like to be able show a formatting hint to my users like "MM/dd/yyyy". Is there a way to get the formatting pattern from a SimpleDateFormat object? 回答1: SimpleDateFormat.toPattern() Returns a pattern string describing this date format. 回答2: If you just need to get a pattern string for the given locale, the following worked for me: /* Obtain the time format