simpledateformat

Can not parse String with Simple Date format

给你一囗甜甜゛ 提交于 2019-12-13 01:07:42
问题 I have a SimpleDateFormat like this : SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); and trying to parse such 2012-Jul-29 17:14:39 but I`m getting java.text.ParseException: Unparseable date: "2012-Jul-29 17:14:39" at java.text.DateFormat.parse(Unknown Source) at com.sysplan.visixd.blastgauge.BGParser.main(Parser.java:396) Any idea why ? 回答1: It appears to be a locale problem, I tried this without any error new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss").parse("2012

Misbehaving of the date parsing in SimpleDateFormat

馋奶兔 提交于 2019-12-12 21:08:22
问题 I have a java class inside the jar file that is in a JBoss server which invoked through a bash file as follows. java -cp /com/site/domain/TimeFormatter.jar packOne.subPack.Test But I got an error when parsing the below date in there. java.text.ParseException: Unparseable date: "Wed, 29 Jan 2014 21:00:00 GMT" at java.text.DateFormat.parse(DateFormat.java:335) Java CODE : Date date = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z").parse("Sun, 26 Jan 2014 21:00:00 GMT"); System.out.println(

时间戳与时间之间的转换

▼魔方 西西 提交于 2019-12-12 20:50:35
时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 1.Java中转换: 时间戳转换为时间: Long timeStamp = System . currentTimeMillis ( ) ; //获取当前时间戳 System . out . println ( timeStamp ) ; SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; String sd = sdf . format ( new Date ( Long . parseLong ( String . valueOf ( timeStamp ) ) ) ) ; // 时间戳转换成时间 System . out . println ( "格式化结果:" + sd ) ; 时间转化为时间戳: SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; String time = "2019-04-44 11:45:55" ; Date date = format . parse ( time ) ; System . out . print (

Java的八大数据类型

社会主义新天地 提交于 2019-12-12 19:07:10
1. Java的简单类型及其封装器类 Java基本类型共有八种,基本类型可以分为三类,字符类型char,布尔类型boolean以及数值类型byte、short、int、long、float、double。数值类型又可以分为整数类型byte、short、int、long和浮点数类型float、double。JAVA中的数值类型不存在无符号的,它们的取值范围是固定的,不会随着机器硬件环境或者操作系统的改变而改变。实际上,JAVA中还存在另外一种基本类型void,它也有对应的包装类 java.lang.Void,不过我们无法直接对它们进行操作。8 中类型表示范围如下: byte :8位,最大存储数据量是255,存放的数据范围是-128~127之间。 short :16位,最大数据存储量是65536,数据范围是-32768~32767之间。 int :32位,最大数据存储容量是2的32次方减1,数据范围是负的2的31次方到正的2的31次方减1。 long :64位,最大数据存储容量是2的64次方减1,数据范围为负的2的63次方到正的2的63次方减1。 float :32位,数据范围在3.4e-45~1.4e38,直接赋值时必须在数字后加上f或F。 double :64位,数据范围在4.9e-324~1.8e308,赋值时可以加d或D也可以不加。 boolean

Java Formatting Date

橙三吉。 提交于 2019-12-12 17:05:09
问题 I am trying to get the current date and format it however i am getting an invalid month of 59. Under is the code Code import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; DateFormat df = new SimpleDateFormat("yyyy-mm-dd"); Date todayDate = new Date(); String formatDate = df.format(todayDate); Output is 2013-59-07 回答1: You need "MM" for month. "mm" is for minutes. See http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html 回答2: You have used

How do I convert the following String Date into Java Data format in Java?

馋奶兔 提交于 2019-12-12 13:17:46
问题 How do i convert the following String Date into Data format in Java? "10/01/2012 06:45:23:245946" I am using the following code dateFormat = new SimpleDateFormat("MM/dd/yyyy hh24:mm:ss:SSS"); java.util.Date parsedDate = dateFormat.parse("10/01/2012 06:45:23:245946"); And i am getting the following error java.text.ParseException: Unparseable date: "10/01/2012 06:45:23:245946" 回答1: There is no hh24 in SimpleDateFormat, You should be using HH 回答2: Your pattern is wrong. Try: "MM/dd/yyyy HH:mm:ss

Convert UTC Date to local Date

好久不见. 提交于 2019-12-12 13:10:20
问题 I am converting from epoch time (which is in UTC) to a format as shown below. Now I tried different SO answers to convert UTCDate from UTC to local time. But I am not getting the local time. Any help would be appreciated. String epochTime = "1436831775043"; Date UTCDate = new Date(Long.parseLong(epochTime)); Date localDate; // How to get this? SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a"); String result = simpleDateFormat.format(UTCDate); Also, the conversion has to be

Java: epoch date to MM/DD/YYYY

假装没事ソ 提交于 2019-12-12 12:26:23
问题 My time: 1386696238 My code: Date date = new Date(Long.parseLong(currentNotification.getDate_created())); SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault()); String dateString = formatter.format(date); My result: 1/16/1970 Desired result: 12/10/2013 What am I doing wrong? 回答1: Your value is in seconds, so you need to multiply it by 1000. Also, DD is day of year, you want dd : SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault())

计算出生年龄按规则输出

流过昼夜 提交于 2019-12-12 12:00:44
需求 具体就是根据出生时间判断是出生多久,并且按照出生的时间范围决定输出格式。 1星期内 : x天xx小时 1星期以上-1个月以内 : xx天 1个月以上-1周岁以内 : xx月xx天 1周岁以上-3周岁以内 : xx岁xx月 3周岁以上 : xx岁 思路 重点: 1使用Calendar类进行把出生时间和当前时间进行相减获取出生时间。 2通过出生时间计算出出生的总天数,并且使用总天数来进行范围的区分。 3考虑输入是yyyy-MM-dd HH:mm:ss,使用截取StringUtils工具类。 注意 Calendar类 月份指针是0代表1月,1代表二月,润平年的区分 上码 依赖 < dependency > < groupId > commons - lang < / groupId > < artifactId > commons - lang < / artifactId > < version > 2.6 < / version > < / dependency > public static void main ( String [ ] args ) throws ParseException { String s = parseAge ( "2015-11-11 08:06:00" ) ; System . out . println ( s ) ; } public

Is this a Java DateFormat bug?

浪子不回头ぞ 提交于 2019-12-12 11:52:22
问题 The pattern is "dd-MM-yyyy" I think the string "01-01-2010mwwwwwwwwwwwwwww" does not satisfy the pattern, but the following code shows the contrary. Anyone can explain why? public static void main(String[] args) throws Exception { SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy"); Date date = df.parse("01-01-2010mwwwwwwwwwwwwwww"); System.out.println(date); } Thanks 回答1: The parse method does not try to match the entire input string. That is, the prefix 01-01-2010 matches, and that's