simpledateformat

Conversion of a date to epoch Java [duplicate]

陌路散爱 提交于 2019-12-23 07:07:20
问题 This question already has answers here : SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm” (4 answers) Closed last year . I want to convert 2018-02-21 15:47:35 UTC to epoch UTC form. How do we do it? I am currently in PST. SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS"); df.setTimeZone(TimeZone.getTimeZone("UTC")); date = df.parse(dateString).getTime(); The code above should return the number of milliseconds since January 1, 1970, 00:00:00 GMT , but

Parse short US date into yyyy-MM-dd, java

吃可爱长大的小学妹 提交于 2019-12-23 03:34:10
问题 I want to parse the date "3/27/11" which I think is equal to US short date. DateFormat df1 = new SimpleDateFormat("MM/dd/yy"); DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd"); Date date = (Date) df1.parseObject("03/27/11"); System.out.println("New date: " + df2.format(date)); I found the code above in several java tutorials but it doesn't seem to work. For some how I get, Exception in thread "main" java.lang.AssertionError: Default directory must be absolute/non-UNC Here is what I want to

am/pm strings not localized/translated when using DateFormat

倖福魔咒の 提交于 2019-12-22 20:05:32
问题 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()); 回答1:

Strange date and time parsing result with SimpleDateFormat

谁说我不能喝 提交于 2019-12-22 07:13:26
问题 I have a strange problem when parsing a ISO8601 date and time with SimpleDateFormat. The relevant code is: public class DateHelper { private static SimpleDateFormat iso8601formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); public static Date parseISO8601(String date) throws ParseException { Date result = iso8601formatter.parse(date); return result; } } For input I'm giving it a string 2010-09-06T15:30:00+02:00 And as a return I get a Date object with date set to 6th of January 2010

Strange date and time parsing result with SimpleDateFormat

吃可爱长大的小学妹 提交于 2019-12-22 07:13:12
问题 I have a strange problem when parsing a ISO8601 date and time with SimpleDateFormat. The relevant code is: public class DateHelper { private static SimpleDateFormat iso8601formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); public static Date parseISO8601(String date) throws ParseException { Date result = iso8601formatter.parse(date); return result; } } For input I'm giving it a string 2010-09-06T15:30:00+02:00 And as a return I get a Date object with date set to 6th of January 2010

Strict 24-hour time in JFormattedTextField

你离开我真会死。 提交于 2019-12-22 05:19:31
问题 I am trying to create a JFormattedTextField that only accepts a 24-hour time. I am very close to a solution, but have one case where the following code example does not work. If you enter the time "222" and change focus from the field, the time is corrected to "2202". I would like it to only accept a full 4 digit 24-hour time. This code works as I want in almost all cases, except the one I just mentioned. Any suggestions? public static void main(String[] args) throws ParseException {

How do I convert an Arabic String date to a java 8 date object?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 03:42:34
问题 I'm working on a web monitoring project in Arabic and I want to convert string date like this one: الاثنين 24 أبريل 2017 - 15:00 to Java 8 date object. How can I do that? 回答1: Edit: with thanks to slim and Meno Hochschild for inspiration: String dateTimeString = "الاثنين 24 أبريل 2017 - 15:00"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE d MMMM uuuu - HH:mm", new Locale("ar")); LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, formatter); System.out.println

Java Date Parsing “a.m.” and “p.m.”

隐身守侯 提交于 2019-12-21 19:17:13
问题 Using SimpleDateFormat, how can you parse the String: "2013-05-23T09:18:07 p.m..380+0000" All my SimpleDateFormat Strings are tripping up on the "p.m." part. Thanks in advance. EDIT: We have no control over the format coming in. I've tried: "yyyy-MM-dd'T'HH:mm:ss a.a..SSSZ" "yyyy-MM-dd'T'HH:mm:ss aaaa.SSSZ" "yyyy-MM-dd'T'HH:mm:ss a.'m'..SSSZ" "yyyy-MM-dd'T'HH:mm:ss a.'m.'.SSSZ" "yyyy-MM-dd'T'HH:mm:ss a.'m..'SSSZ" "yyyy-MM-dd'T'HH:mm:ss aa'm'..SSSZ" "yyyy-MM-dd'T'HH:mm:ss aa'm.'.SSSZ" "yyyy-MM

3.lombok系列3:lombok的实验类特性

无人久伴 提交于 2019-12-21 11:31:03
转自:https://blog.csdn.net/54powerman/article/details/72516755 lombok除了已经推荐使用的基本功能,还维护了一个创新型的注解,有些功能有违常规对java认知,或者只支持eclipse,其他IDE支持有问题,甚至某些环境完全不可用。因此没有正式使用。 但是的确很有创意,这些注解已经在jar中提供,只不过它是归在”lombok.experimental. ” 包中;而基本功能在”lombok. ” 包中。 @Accessors 定制流畅的访问器。 @Accessors(chain=true) 链式访问,该注解设置 chain=true ,生成setter方法返回this,代替了默认的返回void。 package com.pollyduan; import lombok.Data; import lombok.experimental.Accessors; @Data @Accessors(chain=true) public class User { private Integer id; private String name; private Integer age; public static void main(String[] args) { User user=new User().setAge(31)

How to format the Spanish month in sentence case using SimpleDateFormat?

余生颓废 提交于 2019-12-21 10:56:07
问题 This is my code : /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.text.SimpleDateFormat; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { SimpleDateFormat date = new SimpleDateFormat("dd-MMM-yyyy", new Locale("es","ar")); System.out.println(date.format(new Date(2014-1900,0,1))); } } The above code returns, 01-ene