simpledateformat

TimeZone broken in SimpleDateFormat in android 2.3

穿精又带淫゛_ 提交于 2019-12-06 14:37:46
Android 2.3 was recently released last night. So naturally I tried my app on it and found there was date formatting issue. I have noticed the DateFormatter produces different formats. So do this in a simple Java program: ((SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)).format(new Date()); Output is December 7, 2010 11:49:40 AM EST Do the same thing in an android emulator and you get December 7, 2010 11:42:50 AM GMT-05:00 Notice the different time zone. Has anybody ran in to this issue? Is there another formatter I can use that doesn't depend on Java's

JAVA 日期格式转换设置

别来无恙 提交于 2019-12-06 14:28:55
/** * 工具类-日期处理 */ public class DateUtil { import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; /** * 获取当前日期年月日时分秒yyyy-MM-dd HH:mm:ss * * @return */ public static String getDateTime() { SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date now = new Date(); return simpleFormat.format(now); } /** * 获取当前日期年月日时分秒yyyy-MM-dd */ public static String getDateYMD() { SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd"); Date now = new Date(); return simpleFormat.format(now); } /** * 将string日期 转为 date

Convert java.time.LocalDate to java.util.Date

我是研究僧i 提交于 2019-12-06 12:52:01
I have java.time.LocalDate Object in yyyy-MM-dd format. I would like to know how to convert this to java.util.Date with MM-dd-yyyy format. getStartDate() method should be able to return Date type object with the format MM-dd-yyyy. DateParser class package com.accenture.javadojo.orgchart; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.Locale; public class DateParser { public static LocalDate parseDate(String strDate){ try{ if((strDate != null) && !("").equals(strDate)){ DateTimeFormatter formatter =

时间日期

拟墨画扇 提交于 2019-12-06 12:39:38
日期格式有date,String或者datetime挥着 时间戳 时间在计算机中是以整数形式存在的,存放的时间距时间原点过多少毫秒,------------System.currentTimeMillis()获得现在距时间原点的毫秒数; SimpleDateFormat对时间进行自定义显示;SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-MM-S"); Calendar是设置指定时间 在java8中有一个叫Localdate的类有很多方法可以获取时间日期还有对日期进行操作 另外在数据库中,date,String或者datetime、timestamp(时间戳) date格式不能显示时分秒,只能显示日期,时间全是0; datetime有8个字节,能显示日期时间,但是它不会随时区的改变而改变;datetime允许为空值,可以自定义值,系统不会自动修改其值。不可以设定 默认值 ,所以在不允许为空值的情况下,必须手动指定datetime字段的值才可以成功插入数据。 timestamp有四个字节允许为空值,但是不可以自定义值,所以为空值时没有任何意义。而timestamp大致与datetime相同,不一样的地方就是回随着时区变化而变化,.时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区。

Android: I can't figure out SimpleDateFormat

喜夏-厌秋 提交于 2019-12-06 12:02:58
问题 I have tried and tried, but I cannot get my RSS app to properly format the pubDate into a more user friendly format. String str = "26/08/1994"; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); //please notice the capital M Date date = formatter.parse(str); That code looks simple enough, but I get an unhandled type parse exception error on formatter.parse(str). Once that gets working, I then need to convert my RSS Pubdate to MM/dd. The line of code to set the text for that is

java处理特殊时间格式2019-11-28T06:52:09.724+0000诸如此类,并转为常见格式,同时转为数据库日期格式Timestamp

余生颓废 提交于 2019-12-06 10:59:31
  public static final String FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String FORMAT_T = "yyyy-MM-dd'T'HH:mm:ss"; public static final String FORMAT_Z = "EEE MMM dd HH:mm:ss Z yyyy"; /** * 处理时间格式 2019-11-28T06:52:09.724+0000 为 yyyy-MM-dd HH:mm:ss * */ public static String dealDateFormat(String oldDate) { Date date1 = null; DateFormat df2 = null; try { DateFormat df = new SimpleDateFormat(ExchangeConstants.FORMAT_T); Date date = df.parse(oldDate); SimpleDateFormat df1 = new SimpleDateFormat (ExchangeConstants.FORMAT_Z, Locale.UK); date1 = df1.parse(date.toString()); df2 = new

Adding days with java.util.Calendar gives strange results

倖福魔咒の 提交于 2019-12-06 09:21:11
问题 Using java.util.Calendar to add a single day to a Date, and SimpleDateFormat to display the result, sometimes seems to lose a day (generally in March) and sometimes skips a day (in November). The program below, with output, illustrates the issue. Notice that I'm just adding one day at a time, then skipping a few months and adding a few more days. You'll see that 2008-03-09 gets printed twice, but 2008-11-02 is skipped. The same thing happens in other years, but on different days. I had to

Java 7 Calendar.getInstance, TimeZone.getTimeZone got synchronized and slow, any work arounds?

断了今生、忘了曾经 提交于 2019-12-06 07:28:06
问题 After upgrading my runtime to Java 7 I see incredible slowness... and my program is spending all of its time in the SimpleDateFormat constructor. As described in a great post here: http://coffeedriven.org/?p=83 the TimeZone code is now checking for the presence of an application context in the static synchronized method getDefaultInAppContext() . The problem for me is that it's Spring Batch file reader code that is creating a new SimpleDateFormat object for each line that it reads! Anyone got

am/pm strings not localized/translated when using DateFormat

不想你离开。 提交于 2019-12-06 06:12:42
When my app loads, I get device's settings in order to display dates/times according to user's locale. As seen on the image below, the pattern is correct, but the am/pm marker is not translated to the corresponding language (in this case language is Greek, local is "el_GR"). Is there a way to fix that? "am/pm" should be automatically translated to "πμ/μμ" public static final DateFormat USER_DF_TIME = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()); kouretinho After further investigation, I found a similar bug for Java 6, "Swedish localization has

Difference between hh:mm a and HH:mm a

爷,独闯天下 提交于 2019-12-06 06:00:36
问题 Here is my original code- String dateString = "23 Dec 2015 1:4 PM"; Locale locale = new Locale("en_US"); SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm a"); DateFormat df = new SimpleDateFormat("dd MMM yyyy HH:mm a", locale); Date date = null; try { date = formatter.parse(dateString); } catch (ParseException e) { LOGGER.error(e); } String newDate = df.format(date); System.out.println("oldDate = " + dateString); System.out.println("newDate = " + newDate); and here is my