simpledateformat

Android SimpleDateFormat fails to parse datetime (works fine on sun 1.6 jre)

不羁岁月 提交于 2019-12-24 10:52:13
问题 Any ideas why the followng fails on Android 2.2... java.text.ParseException: Unparseable date: 2011-02-16 11:38:03.328 UTC ...while it works fine on a sun JRE 1.6 ? DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z"); try { Date date = dateFormat.parse("2011-02-16 11:38:03.328 UTC"); } catch (ParseException e) { e.printStackTrace(); } As mentioned ion Comment, can make the test even simpler: new SimpleDateFormat("z").parse("UTC") This throws a parse exception. I am using a

Utilities function in Google App Scripts not working

痴心易碎 提交于 2019-12-24 03:56:15
问题 Function Utilities.formatDate in Google App Scripts is not working correct for date in year 2013 Example- date = Tue Dec 31 2013 18:43:12 GMT+0530 (IST) after formatting it in YYYYMMdd format using code- Utilities.formatDate(date, "IST" ,"YYYYMMdd")) result was- 20**14**1231 In the above result year is expected to be 2013 as per above mentioned date. The same code is working correct for date in 2012 and 2014. 回答1: Just change your pattern from YYYY to yyyy (lower case) and it will work, check

修改记录

大兔子大兔子 提交于 2019-12-24 00:04:25
一: 实现普通用户的session共享 二.超管redis共享tocken 1.在第一步的RedisCacheManager类中多放入一个cache,取个别名就行,不用重新创建 Cache cache = caches.get(name); if (cache == null) { cache = new RedisCache(redisTemplate); caches.put(name, cache); //超管登录时使用,实际就是原来的cache caches.put("superTicket", cache); } 2.直接替换SuperAdminTicketUtils类就可以,下面详情可忽略------------【序列化、修改引用、不可忽略】 2.把SuperAdminTicketUtils类的static方法都删掉,引用这个类中static方法放入类都改一下引用方式如下:【要把这个类交给spring去管理,加个注解就就好】 @Componentpublic class SuperAdminTicketUtils{ ------------------------------------------------------------------------@Autowired private SuperAdminTicketUtils

How do I set timezone on a specific date? [duplicate]

这一生的挚爱 提交于 2019-12-23 23:24:51
问题 This question already has answers here : Get GMT Time in Java (10 answers) How to Parse Date from GMT TimeZone to IST TimeZone and Vice Versa in android (4 answers) Closed 4 months ago . I have an issue where I tried all ways(including online stackoverflow threads), but am not able to set timezone as expected on a specific date. Here's my code: Date until = DateTimeUtils.getNewBookUntilDate(); //which returns : Wed Aug 28 11:00:02 EDT 2019 SimpleDateFormat isoFormat = new SimpleDateFormat(

Error using SimpleDateFormat

你离开我真会死。 提交于 2019-12-23 16:19:48
问题 I'm trying to use the SimpleDateFormat class to parse a DateTime out of this string: 05-Jul-2012 11:38:02,442 UTC AM I tried the following format string: SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS z a"); Date temp = dateformatYYYYMMDD.parse(time); But it generates the error: Error: Unparseable date: "" If I use zZ I get : Error: Unparseable date: "05-Jul-2012 11:38:02,442 UTC AM" Any hints on how to get around this? 回答1: That works fine for me when I

getting month name wrong with SimpleDateFormat

大兔子大兔子 提交于 2019-12-23 12:43:08
问题 I am having problem with this small piece of code SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss"); String str = "2010-03-13 01:01:22"; Date date = sf.parse(str); SimpleDateFormat f = new SimpleDateFormat("d MMM yyyy hh:mm aaa"); System.out.println(" Date " + f.format(date)); Output : Date 13 Jan 2010 01:01 AM The code seems to be fine but still I am getting month name wrong. Please help !! Thanks. 回答1: You are using minute instead of month in your pattern. It should be: yyyy

Convert GMT DateTime String

混江龙づ霸主 提交于 2019-12-23 11:47:33
问题 I am pretty new to Java and I am a little stuck with using SimpleDateFormat and Calendar . I have a Date-Object and want to extract a GMT datestring like yyyy-MM-dd HH:mm:ss . I live in Germany and at the moment we are GMT +0200. My Date-Object's time is for example 2011-07-18 13:00:00 . What I need now is 2011-07-18 11:00:00 . The offset for my timezone should be calculated automatically. I tried something like this, but I guess there is a fault somewhere: private String toGmtString(Date

格式化String类型数据,并转换成Date类型输出

不问归期 提交于 2019-12-23 10:01:09
格式化String类型数据,并转换成Date类型输出 public class FormatStringToDate { //将String类型的数据格式化为yyyy-MM-dd public Date formatString(String str) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); return simpleDateFormat.parse(str); } public Date formatString1(String str) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); return simpleDateFormat.parse(str); } public Date formatString2(String str) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SS"); return

Getting wrong data when using SimpleDateFormat.parse()

。_饼干妹妹 提交于 2019-12-23 07:48:59
问题 I am getting the strangest error, when trying to parse a string as a calendar. It seems that it messes up the Date object which I use to set the result calendar's time. The error is pretty inconsistent (or I see no logic in it). Can anyone point out what I might be doing wrong ? public class caltest{ public static final SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss.SSS"); public static void main(String[] args) { String date1 = "1992-03-11 12:00:12.123"; String date2 = "1993

Conversion of a date to epoch Java [duplicate]

余生长醉 提交于 2019-12-23 07:08:07
问题 This question already has answers here : SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm” (4 answers) Closed last year . I want to convert 2018-02-21 15:47:35 UTC to epoch UTC form. How do we do it? I am currently in PST. SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS"); df.setTimeZone(TimeZone.getTimeZone("UTC")); date = df.parse(dateString).getTime(); The code above should return the number of milliseconds since January 1, 1970, 00:00:00 GMT , but