Tag: datetime format

无法使用Java 8中的DateTimeFormatter和ZonedDateTime从TemporalAccessor获取ZonedDateTime

我最近转向Java 8,希望能更轻松地处理本地和分区时间。 但是,在我看来,在解析一个简单的日期时,我面临一个简单的问题。 public static ZonedDateTime convertirAFecha(String fecha) throws Exception { DateTimeFormatter formatter = DateTimeFormatter.ofPattern( ConstantesFechas.FORMATO_DIA).withZone( obtenerZonaHorariaServidor()); ZonedDateTime resultado = ZonedDateTime.parse(fecha, formatter); return resultado; } 就我而言: fecha是’15 / 06/2014′ ConstantesFechas.FORMATO_DIA是’dd / MM / yyyy’ obtenerZonaHorariaServidor返回ZoneId.systemDefault() 所以,这是一个简单的例子。 但是,解析会抛出此exception: java.time.format.DateTimeParseException: Text ’15/06/2014′ could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2014-06-15 of […]

将String转换为java.util.Date

我将日期存储在SQLite数据库中,格式如下: d-MMM-yyyy,HH:mm:ss aaa 当我用那种格式检索日期时,除了小时之外,我得到的一切都很好。 小时总是00 。 这是我的输出: String date—>29-Apr-2010,13:00:14 PM After convrting Date—>1272479414000–Thu Apr 29 00:00:14 GMT+05:30 2010 这是代码: Date lScheduledDate = CalendarObj.getTime(); DateFormat formatter = new SimpleDateFormat(“d-MMM-yyyy,HH:mm:ss aaa”); SomeClassObj.setTime(formatter.format(lScheduledDate)); String lNextDate = SomeClassObj.getTime(); DateFormat lFormatter = new SimpleDateFormat(“d-MMM-yyyy,HH:mm:ss aaa”); Date lNextDate = (Date)lFormatter.parse(lNextDate); System.out.println(“output here”+lNextDate); 我究竟做错了什么?

将纪元时间转换为日期

我尝试了一百万种不同的方式,但无济于事。 任何帮助将非常感激。 long millis = getMillisFromServer(); Date date = new Date(millis); DateFormat format = new SimpleDateFormat(“dd/MM/yyyy HH:mm:ss”); format.setTimeZone(TimeZone.getTimeZone(“Australia/Sydney”)); String formatted = format.format(date); 以上不起作用。 基本上,我想要做的是,获取纪元时间并将其转换为澳大利亚时间。 我当地时间是+05.30但当然我不希望这是导致这种转换的因素。 编辑- 运行您的确切代码时的输出, epoch 1318388699000 周五10月12日08:34:59 GMT + 05:30 2011 12/10/2011 03:04:59 12/10/2011 14:04:59

在Java中将Epoch秒转换为日期和时间格式

自1970年1月1日UTC(大纪元时间)以来我有几秒钟。 1320105600 我需要将这些秒转换为以下格式的日期和时间。 2011年11月4日星期五上午5点00分 我怎样才能做到这一点?