simpledateformat

日期工具类

 ̄綄美尐妖づ 提交于 2019-12-20 00:20:37
import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; /** * 日期操作工具类 * * @author hlyangq * * @date 2018年11月1日 上午17:35:14 * */ public class DateUtil { public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String DATE_MI_FORMAT = "yyyy-MM-dd HH:mm"; public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String CH_DATE_FORMAT_YMD = "yyyy年MM月dd日"; public static final String CH_DATE_FORMAT_MD = "MM月dd日"; public static final String DATE

校验微信的返回access_token是否有效,并始终获取配置文件中的有效的access_token

一笑奈何 提交于 2019-12-19 21:44:50
package com . ruoyi . weixin ; import com . alibaba . fastjson . JSON ; import com . alibaba . fastjson . JSONObject ; import com . ruoyi . common . utils . WeiXinToken ; import com . ruoyi . system . domain . SysConfig ; import com . ruoyi . system . mapper . SysConfigMapper ; import com . ruoyi . system . service . ISysConfigService ; import org . apache . commons . lang3 . time . DateUtils ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Service ; import java . text . ParseException ; import java . text .

SimpleDateFormat: unparseable date exception

拟墨画扇 提交于 2019-12-19 17:46:17
问题 After looking after several existing posts, I am still not able to get my SimpleDateFormat parser working. Here is the code: SimpleDateFormat df = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); try { volcanoListDate = df.parse(currentValue); } catch (ParseException e) { Log.d("DEBUG", e.toString()); Log.d("DEBUG", currentValue); } I always end up with a ParseException. Here is the output of the debug messages: 06-09 23:52:17.478: DEBUG/DEBUG(2436): java.text.ParseException:

Convert date string (EST) to Java Date (UTC)

喜欢而已 提交于 2019-12-19 10:25:40
问题 I need some advice on this java method. The intent of this method is to take a string that represents a date - this string was created from a date in the EST time zone - and convert it to a java Date object in the UTC time zone. private Date buildValidationDate(String dateString) throws ParseException { System.out.println("dateString " + dateString); SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy hh:mm a"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormat

Java - unparseable date, need format to match “GMT-0400”

不想你离开。 提交于 2019-12-19 10:13:44
问题 I have the following Java: DateFormat formatter = new SimpleDateFormat( "EEE MMM dd yyyy HH:mm:ss zZ (zzzz)", Locale.ENGLISH); Calendar cal = Calendar.getInstance(); cal.set(2011, Calendar.APRIL, 1); out.println(formatter.format(cal.getTime())); out.println(); Date date; try { date = formatter .parse("Fri Apr 01 2011 00:00:00 GMT-0400 (Eastern Daylight Time)"); } catch (ParseException e) { out.println("Failed to parse date: " + e.getMessage()); e.printStackTrace(out); } This is in a servlet,

SimpleDateFormat add some minutes

回眸只為那壹抹淺笑 提交于 2019-12-19 10:06:14
问题 Im trying parse a date from a JSONObject "timcre_not":"2013-12-11 21:25:04.800842+01" and I parse with mDate = new SimpleDateFormat("y-M-d h:m:s.SSSSSSZZ", Locale.ENGLISH).parse(json.getString("timcre_not")); but the mDate value is: Wed Dec 11 21:38:24 CET 2013 What is happening? 回答1: The answer by treeno is correct. Joda-Time As an alternative, you can use the third-party open-source Joda-Time. Joda-Time is often used to supplant the java.util.Date & Calendar classes found in Java (and

convert date and time in any timezone to UTC zone

落花浮王杯 提交于 2019-12-19 01:20:34
问题 this is my date " 15-05-2014 00:00:00 " how to convert IST to UTC i.e( to 14-05-2014 18:30:00) based on from timezone to UTC timezone. my code is DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("IST")); //here set timezone System.out.println(formatter.format(date)); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); //static UTC timezone System.out.println(formatter.format(date)); String str = formatter.format(date); Date date1

Java中的日期与时间

痴心易碎 提交于 2019-12-18 16:13:20
目录 日期与时间 Date DateFormat Calendar Locale @(Java 中的日期与时间) 日期与时间 最常用的几个类,Date、DateFormat、Calendar、Locale Date 1.无参构造方法 //根据当前系统默认的毫秒值创建时间对象 public Date() { this(System.currentTimeMillis()); } 2.根据毫秒值创建时间对象 long time = 1000*60*60; Date d = new Date(time); 3.传入年月日时分秒创建时间对象 Date d2 = new Date(20,10,10,11,11,11) //这得到的时间并不是20-10-10这种 //下面是源码 public Date(int year, int month, int date, int hrs, int min, int sec) { int y = year + 1900; // month is 0-based. So we have to normalize month to support Long.MAX_VALUE. if (month >= 12) { y += month / 12; month %= 12; } else if (month < 0) { y += CalendarUtils

Java String to Date object of the format “yyyy-mm-dd HH:mm:ss”

偶尔善良 提交于 2019-12-18 14:16:47
问题 I need to convert a String containing date into an date object. The String will be of the format "yyyy-mm-dd HH:mm:ss.SSSSSS" and I want the same format in an date object. For instance I have a string "2012-07-10 14:58:00.000000", and I need the resultant date object to be of the same format. I have tried the below methods but, the resultant is not as expected. java.util.Date temp = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss.SSSSSS").parse("2012-07-10 14:58:00.000000"); DateFormat dateFormat =

java.text.SimpleDateFormat not thread safe

橙三吉。 提交于 2019-12-18 13:20:57
问题 Synchronization Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally The above line is mentioned in the JavaDoc of SimpleDateFormat class. Does it mean that we should not create the SimpleDateFormat objects as Static. And If we create it as static, so wherever we are using this object we need to keep it in Synchronised Block. 回答1: Yes SimpleDateFormat is