Tag: simpledateformat

java.text.ParseException:无法解析的日期:将mm / dd / yyyy字符串转换为日期

当我将我的字符串对象以mm/dd/yyyy格式转换为Date它给了我 java.text.ParseException: Unparseable date: “09/17/2014” 我想这样做: String date= “09/17/2014”; DateFormat df = new SimpleDateFormat(); Date journeyDate= (java.sql.Date) df.parse(date);

SimpleDateFormat字符串

我有这个代码块,其中dateFormat.format将始终是一个string这就是我在这里做.toString()原因。 我收到错误“无法将给定对象格式化为日期”。 有没有办法做到这一点? 请注意,字符串来自数据库我在这里使用了新的Date()作为示例。 SimpleDateFormat dateFormat = new SimpleDateFormat(“MMMMM dd, yyyy”); String sCertDate = dateFormat.format(new Date().toString());

将TZ格式的字符串转换为Date

可能的解决方案: 将Java Date转换为另一个Time as Date格式 我经历过但没有得到答案。 我有一个字符串“ 2013-07-17T03:58:00.000Z ”,我想将它转换为我们在制作新Date()时获得的相同forms的日期。日期d =新Date(); 时间应该在IST.Zone-Asia / Kolkata 因此,上面字符串的日期应该是 7月17日星期三12:05:16 IST 2013 //根据印度标准GMT + 0530的时间 String s=”2013-07-17T03:58:00.000Z”; DateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSSZ”); TimeZone tx=TimeZone.getTimeZone(“Asia/Kolkata”); formatter.setTimeZone(tx); d= (Date)formatter.parse(s);

Java String to Date对象格式为“yyyy-mm-dd HH:mm:ss”

我需要将包含日期的String转换为日期对象。 字符串的格式为“yyyy-mm-dd HH:mm:ss.SSSSSS”,我想在日期对象中使用相同的格式。 例如,我有一个字符串“2012-07-10 14:58:00.000000”,我需要生成的日期对象具有相同的格式。 我已经尝试了以下方法,但结果并不像预期的那样。 java.util.Date temp = new SimpleDateFormat(“yyyy-mm-dd HH:mm:ss.SSSSSS”).parse(“2012-07-10 14:58:00.000000”); DateFormat dateFormat = new SimpleDateFormat(“yyyy-mm-dd HH:mm:ss”); Date thisDate = dateFormat.parse(“2012-07-10 14:58:00.000000”); 结果是“Tue Jan 10 14:58:00 EST 2012”。 请让我知道我哪里出错了。 谢谢,Yeshwanth Kota

java.text.SimpleDateFormat不是线程安全的

Synchronization Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally 上面的行在SimpleDateFormat类的JavaDoc中提到。 这是否意味着我们不应该将SimpleDateFormat对象创建为Static。 如果我们将其创建为静态,那么无论我们在何处使用此对象,我们都需要将其保存在Synchronized Block中。

如何提高ThreadLocal包装的SimpleDateFormat的性能?

这是在RHEL上的Java 7(51)上有24个内核我们注意到,当我们增加线程池大小时,包含在本地线程中的java SimpleDateFormat的平均响应时间会增加。 这是预期的吗? 或者,我只是在做一些愚蠢的事情? 测试程序 public class DateFormatterLoadTest { private static final Logger LOG = Logger.getLogger(DateFormatterLoadTest .class); private final static int CONCURRENCY = 10; public static void main(String[] args) throws Exception { final AtomicLong total = new AtomicLong(0); ExecutorService es = Executors.newFixedThreadPool(CONCURRENCY); final CountDownLatch cdl = new CountDownLatch(CONCURRENCY); for (int i = 0; i […]

SimpleDateFormat的结果不正确

我想将Tue Jun 01 00:00:00 IST 112转换为01-JUN-2012 我用了 Calendar calendar = new GregorianCalendar(year, 6, Calendar.DAY_OF_MONTH); Date maxDate=new Date(); maxDate=calendar.getTime(); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); SimpleDateFormat s=new SimpleDateFormat(“dd-mmm-yyyy”); s.format(maxDate); 但我得到30-000-0112

SimpleDateFormat显示分钟,秒和毫秒错误

我已经编写了这个示例程序,我希望将日期转换为另一种格式。 使用简单的日期格式时,我看不到预期的日期。 public class TestDate { /** * @param args */ public static void main(String[] args) { SimpleDateFormat originalformat = new SimpleDateFormat(“yyyy-MM-dd-HH.mm.ss.SSSSSS”); SimpleDateFormat targetformat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSSSSS”); try { //Use Simple Date Format Date date = originalformat.parse(“2015-04-09-17.18.48.677862”); System.out.println(“Using SDF “+targetformat.format(date)); //Use Manual Translation String eventTime = “2015-04-09-17.18.48.677862”; StringBuffer timeBuffer = new StringBuffer(); for (int […]

Java Unparseable Date Exception

我试图用正斜杠替换连字符,但它导致一个unparseable date exception String test = “2014-04-01 05:00:00”; Date date = new SimpleDateFormat(“YYYY/MM/dd hh:mm:ss”, Locale.ENGLISH).parse(test); System.out.println(date); 我有转换的必要值,有人能告诉我为什么它会返回错误吗? 另外,我想在格式的末尾附加一个am/pm marker ,这可能吗?

更改日期格式

我无法将日期格式更改为dd/MMM/yyyy 。 这是我目前的实施: final String OLD_FORMAT = “yyyy-MM-dd”; final String NEW_FORMAT = “yyyy-MMM-dd”; //Start Date String str4=label.getText(); java.util.Date toDate = null; //System.out.println(str4); //End Date String str5=lblNewLabel_3.getText(); java.util.Date newDateString = null; SimpleDateFormat format = new SimpleDateFormat(OLD_FORMAT); try { toDate=format.parse(str4); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { newDateString=format.parse(str5); format.applyLocalizedPattern(NEW_FORMAT); } […]