simpledateformat

Parsing Java dates with truncated timezone information

余生颓废 提交于 2019-12-10 19:20:45
问题 Consider the following date string 2012-10-01 01:02:03.004+0500 This is recognized in Java using the following SimpleDateFormat pattern: yyyy-MM-dd HH:mm:ss.SSSZ If, however, the timezone information above is truncated to 2 digits, i.e. like 2012-10-01 01:02:03.004+05 the date string does not comply to any valid format, so there is no SimpleDateFormat pattern that could be used in order to correctly parse it. Is there any workaround for parsing the truncated timezone correctly without string

SimpleDateFormat problems with 2 year date

女生的网名这么多〃 提交于 2019-12-10 18:35:48
问题 I'm trying to understand two things: Why doesn't the following code throw an exception (since the SimpleDateFormat is not lenient) It doesn't throw an exception, but why is it parsing the year as 0013 (instead of using the rules here the +80:-20 years from today rule) Here's the code import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class TestDate { public static void main(String[] args) throws Exception { SimpleDateFormat format = new

ThreadLocal and SimpleDateFormat array

廉价感情. 提交于 2019-12-10 18:02:57
问题 Using a pattern very similar to that described in a recent question, for a multithreaded application, I am getting weird date values (e.g., years like 2025 or 2035, when clearly no such value exists in the source data). It seems that a concurrency issue is occuring. The source code looks something like // Various Java DateFormat patterns, e.g. "yyyy-MM-dd". private static final String[] DATE_PATTERNS = new String[] {...}; private static SimpleDateFormat[] getFormats(final String[] patterns) {

最全时间工具类timeUtile

江枫思渺然 提交于 2019-12-10 17:55:43
写代码最烦的是什么,写个日期啥,或者判断一个日期是什么星座还要写一大推代码,岂不是很累,伸手党福利来了 import android.support.annotation.NonNull; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import 自己的路径.TimeConstants; /** * @author xiaoye * @fileName TimeUtils * @createDate 2018/11/5 9:26 * @email 1025982282@qq.com * @desc 全局统一Toast工具类 */ public final class TimeUtils { private TimeUtils(){ throw new UnsupportedOperationException("u can't

convert date from “2009-12 Dec” format to “31-DEC-2009”

﹥>﹥吖頭↗ 提交于 2019-12-10 16:46:19
问题 '2009-12 Dec' should be converted to '31-DEC-2009' '2010-09 Sep' should be converted to '30-SEP-2010' '2010-02 Feb' should be converted to '28-FEB-2010' '2008-02 Feb' should be converted to '29-FEB-2008' The values 2009-12 Dec , 2008-02 Feb will be displayed to the User in a drop down. The User have no option to select the DAY . The user selected value should be passed to the Database. But the database expects the date in the format DD-MMM-YYYY . The query has ' <= USER_DATE ' condition. So,

Scala中日期类型的数据

三世轮回 提交于 2019-12-10 16:46:18
import java . text . SimpleDateFormat object TimeStampTest { // maim def main ( args : Array [ String ] ) : Unit = { // 获取系统的时间戳 val tsLong = System . currentTimeMillis ( ) //println(tsLong) // 1575871214234 // 根据获取的时间戳 计算系统的时间 val sdf0 = new SimpleDateFormat ( "HH:mm:ss" ) . format ( tsLong ) //println(sdf0) // 14:00:14 // 代码调试 val sdf1 = new SimpleDateFormat ( "HH:mm:ss" ) . format ( 1575871214234 L ) println ( sdf1 ) // 14:00:14 val sdf2 = new SimpleDateFormat ( "HH:mm:ss" ) . format ( 1575871214000 L ) println ( sdf2 ) // 14:00:14 // 代码调试 val sdf3 = new SimpleDateFormat ( "HH:mm:ss" ) .

Format milliseconds to simpledate format

你离开我真会死。 提交于 2019-12-10 15:01:15
问题 I'm facing a weird result when formatting milliseconds to a SimpleDate format: Output is: Start date time: 11/06/30 09:45:48:970 End date time: 11/06/30 09:45:52:831 Execution time: 01:00:03:861 Script: long dateTimeStart = System.currentTimeMillis(); // some script execution here long dateTimeEnd = System.currentTimeMillis(); "Start date time: " + GlobalUtilities.getDate(dateTimeStart, "yy/MM/dd hh:mm:ss:SSS"); "End date time: " + GlobalUtilities.getDate(dateTimeEnd, "yy/MM/dd hh:mm:ss:SSS")

SimpleDateFormat Ignore Characters

不羁岁月 提交于 2019-12-10 13:10:59
问题 I am using a SimpleDateFormat and I am getting results from two different sources. One source uses the format "yyyy-MM-dd HH:mm:ss" , while the other uses "yyyy-MM-ddTHH:mm:ssZ" . I am not interested in obtaining the time zone ('Z' value) from the second format, is there a way I can obtain these times without using different format strings? Something that will ignore the middle character as well as the characters after 'ss' . 回答1: The cleanest and clearest solution is if you can separate the

Remove Leading “0” in day of month SimpleDateFormat

孤街醉人 提交于 2019-12-10 12:41:33
问题 Is it possible to remove the "0" in January 04, 2012? I am currently using the following Java to get the date format like Monday, January 04, 2012 I would like for it to look like Monday, January 4, 2012 Date anotherCurDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM dd', ' yyyy"); final String formattedDateString = formatter.format(anotherCurDate); final TextView currentRoomDate = (TextView) this.findViewById(R.id.CurrentDate); 回答1: SimpleDateFormat

java.text.ParseException: Unparseable date: “Wed Jan 11 00:00:00 CET 2012”

不问归期 提交于 2019-12-10 11:44:55
问题 I have the next problem with this date: java.text.ParseException: Unparseable date: "Wed Jan 11 00:00:00 CET 2012" I have this: DateFormat formatter ; Date dateIn=null; formatter = new SimpleDateFormat( "EEE MMM dd HH:mm:ss yyyy" ); try { dateIn = (Date)formatter.parse(dateI); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } What I'm doing bad?. Thanks 回答1: Use timezone and also a locale SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy", Locale.US); to