简体   繁体   English

不使用SimpleDateFormat或Calendar将String类型的日期转换为java.util.Date类型

[英]Convert a date of String type to java.util.Date type without using SimpleDateFormat or Calendar

I'm fetching a date which is of String type but I need the Date type of it. 我正在获取一个String类型的日期,但是我需要它的Date类型。 I'm working in a gwt project so I cannot use SimpleDateFormat or Calendar (which doesn't work in the runtime and throws source code not found exception) 我在gwt项目中工作,因此无法使用SimpleDateFormat或Calendar(在运行时中不起作用,并抛出未找到源代码的异常)

new Date(stringDate) is deprecated so any other way I could do it? 不推荐使用新的Date(stringDate),所以我可以采用其他任何方式吗?

check this 检查这个

String myString = "Thu Nov 18 11:53:45 BST 2014";
DateTimeFormat sdf = DateTimeFormat.getFormat("EEE MM dd HH:mm:ss z yyyy");
Date myDate = sdf.parse(myString);

For more details check this 有关更多详细信息,请检查
I hope this could help! 希望对您有所帮助!

Assuming you have a Date (java.sql.Date) in the format yyy-mm-dd you can call 假设您有一个Date (java.sql.Date) ,格式为yyy-mm-dd ,则可以调用

Date.valueOf("1996-12-12") which returns a Date instance Date.valueOf("1996-12-12")返回Date实例

If you use Date (java.util.Date) you can call 如果使用Date (java.util.Date) ,则可以调用

new Date(System.currentTimeMillis()) which returns a Date instance new Date(System.currentTimeMillis())返回Date实例

Edit GWT has DateTimeFormat which you can use 编辑 GWT具有DateTimeFormat可以使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用SimpleDateFormat或Calendar的情况下获取比当前日期早一年的java.util.Date - How to get a java.util.Date which is a year back than the current date without using SimpleDateFormat or Calendar java.util.date/Calendar/SimpleDateFormat:在java中添加/增加月份 - java.util.date/Calendar/SimpleDateFormat: Adding/Incrementing the months in java 无法将“java.lang.String”类型的值转换为所需类型“java.util.Date” - Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' 无法将 java.lang.String 类型的值转换为所需的 java.util.Date 类型 - Failed to convert value of type java.lang.String to required type java.util.Date 如何将“java.lang.String”类型的值转换为所需的“java.util.Date”类型? - How to convert value of type 'java.lang.String' to required type 'java.util.Date'? 无法将类型'java.lang.String'的属性值转换为必需类型'java.util.Date' - Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' 无法将 java.lang.String 类型的属性值转换为所需类型 java.util.Date - Failed to convert property value of type java.lang.String to required type java.util.Date 将 java.util.Date 转换为什么“java.time”类型? - Convert java.util.Date to what “java.time” type? 将 java.time.LocalDate 转换为 java.util.Date 类型 - Convert java.time.LocalDate into java.util.Date type 以(yyyy-MM-dd)格式将String转换为java.util.Date,返回类型为Date - Convert String to java.util.Date in the (yyyy-MM-dd) format with return type of Date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM