simpledateformat

Convert date string from ISO 8601 format to another

送分小仙女□ 提交于 2019-12-25 02:21:17
问题 i have this piece of code , where i am trying to convert a date string from one format to another, and finally i want the date object again. String dateString = "2014-10-04"; SimpleDateFormat oldFormatter = new SimpleDateFormat("yyyy-MM-dd"); Date parsedDate = oldFormatter.parse(dateString); SimpleDateFormat newFormatter = new SimpleDateFormat("dd-MMM-yyyy"); String convertDateStr = newFormatter.format(parsedDate); Date convertedDate = newFormatter.parse(convertDateStr); when i was testing

How to use SimpleDateFormat to show the current Date?

做~自己de王妃 提交于 2019-12-25 02:10:01
问题 i'm trying to get the current date and time formatted, this is my code: Date date = new Date(); SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyyMMdd-HHmm"); String formattedDate=""+FORMATTER.format(date); Log.d("XXxxxXxXXXXxxxXXXxXxxxX",formattedDate); Something is going wrong because i'm getting this string: 19700103-0217 That date is incorrect, I should get something like this: 20111118-1217 How to solve this problem? 回答1: Well, I can help you out but I have my own code. Ask me if

SimpleDateFormat ignoring month when parsing

自作多情 提交于 2019-12-25 01:49:37
问题 The following code is giving me the parsed date as "Wed Jan 13 00:00:00 EST 2010" instead of "Wed Jun 13 00:00:00 EST 2010". Any ideas much appreciated. SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss"); String str = "2010-06-13T00:00:00"; Date date = sf.parse(str); System.out.println(" Date " + date.toString()); 回答1: Try: "yyyy-MM-dd'T'HH:mm:ss" MM means month. mm means minutes. See the documentation for SimpleDateFormat for more details of the supported date and time

Parsing String with spaces to Date, lead to ParseException

为君一笑 提交于 2019-12-25 01:18:53
问题 I have date strings in this form Thu Aug 02 00:00:00 GMT+00:00 2012 I have tried to use this method to parse these String in a Date object public Date fromStringToDate(String data) { Date result; SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm:ss"); try { result = sdf.parse(data); return result; } catch (ParseException e) { e.printStackTrace(); return null; } } But doesn't works and I get this error java.text.ParseException: Unparseable date: "Thu Aug 02 00:00:00 GMT+00:00 2012"

SpringMVC接收String类型时间数值(实体类是Date)转换

狂风中的少年 提交于 2019-12-25 00:55:53
SpringMVC接收String类型字符串 bean实体是Date 加入bind @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值 } 对单独字符串以及实体类bean接收都起效 来源: https://www.cnblogs.com/ukzq/p/12094445.html

SpringFramework的AOP

痞子三分冷 提交于 2019-12-24 23:22:27
1、什么是AOP Aspect Oriented Programming, 面向切面编程 2、AOP的作用 方法的增强。 假如有一个代码,里面有10000个方法,现如今需要修改,例:每个方法里面加一个事务。那需要手写10000次吗?肯定不现实。 public class UserServiceImpl implements UserService { @Override public void create ( ) { System . out . println ( "创建一个用户" ) ; } @Override public void delete ( ) { System . out . println ( "删除一个用户" ) ; } } 3、办法 3.1 手动写(非代理) 显然不现实 public class UserServiceImpl2 implements UserService { private static SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; @Override public void create ( ) { System . out . println ( "创建一个用户" ) ; System . out . println (

Parsing error for French locale with SimpleDateFormat(string,locale)

放肆的年华 提交于 2019-12-24 18:39:27
问题 I have a piece of code like this on my java side: private static DateFormat getHourFormatter(){ //DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(_locale); Locale locale = Locale.FRENCH; //locale : "fr" DateFormat hourFormatter = new SimpleDateFormat( "hh:mm a",locale); //hourFormatter: simpleDateFormat@103068 locale: "fr" hourFormatter.setTimeZone( TimeZone.getTimeZone("GMT") ); return hourFormatter; //hourFormatter: SimpleDateFormat@103068 } protected static boolean

how to get minutes difference between two time in android

被刻印的时光 ゝ 提交于 2019-12-24 13:57:46
问题 public int difftime(String string, String string2) { int hours; int min = 0; int days; long difference ; try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); Date date1 = simpleDateFormat.parse("08:00 AM"); Date date2 = simpleDateFormat.parse("04:00 PM"); difference = date2.getTime() - date1.getTime(); days = (int) (difference / (1000 * 60 * 60 * 24)); hours = (int) ((difference - (1000 * 60 * 60 * 24 * days)) / (1000 * 60 * 60)); min = (int) (difference - (1000 * 60 * 60

SimpleDateFormat() not giving IllegalArgumentException on passing invalid date format

百般思念 提交于 2019-12-24 13:55:03
问题 I passed %%#@-01-01 as date format, but got no exception. Why? SimpleDateFormat df = null; df = new SimpleDateFormat("%%#@-01-01"); 回答1: Quoting the javadoc for SimpleDateFormat: [...] unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted ; they're simply copied into

时间戳比较(在开始时间与结束时间之内)

旧城冷巷雨未停 提交于 2019-12-24 11:52:14
时间戳比较(在开始时间与结束时间之内) 实现思路很简单,一般都用它来做登录判断,比如登录的时候检查该用户是否还在有效期范围内,如果不在开始时间与结束时间之内,那么就表明该用户已经过期; 这样的话,首先就可以想起三个参数,第一个需要获取当前系统时间,因为我们登录的时候需要根据当前时间来判断,该用户是否还在有效期之内,然后再用数据库中获取该用户的开始时间与结束时间,这两个字段需要在数据库中存在; 1.首先,我需要需要编写一个uti类,创建一个函数方法: /** * 时间格式化转换 * @param time * @return */ public static long dateToTimestamp(String time) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = simpleDateFormat.parse(time); long ts = date.getTime()/1000; return ts; } catch (ParseException e) { return 0; } } /** * 传入参数返回布尔类型,在此方法进行逻辑判断,如果当前时间(currenttime)在开始时间(startTime)与结束时间