可能重复: 如何在java中解析日期?
我想将字符串"11-10-10 12:00:00"转换为Date对象,但我无法这样做。你能帮帮我吗?
我有一个日期对象,它的值为“2010年10月11日:00:00”。
DateFormat newDateFormat = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
String strDate = newDateFormat.format(tempDate);
//**i got strDate as strDate is : 11-10-10 12:00:00**
DateFormat newDateFormat1 = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
try {
tempDate = newDateFormat1.parse(strDate);
// **getting tempDate as - Mon Oct 11 00:00:00 IST 2010**
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}发布于 2011-01-03 14:03:13
DateFormat newDateFormat = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
Date d = newDateFormat.parse("11-10-10 12:00:00");
System.out.println(d);这是ideone演示
发布于 2011-01-03 13:58:12
我认为这是Java代码--不是我的专长--但我认为您的问题是格式字符串中的"hh“,这导致parse将"12:00:00”解释为午夜而不是中午。试着把它改成"HH“,看看这个解析是否正确。
发布于 2011-01-03 14:05:13
你需要用CultureInfo来表示印地语,这是“嗨-IN”。有关区域性的完整列表,请检查此链接CultureInfo
class Program
{
static void Main(string[] args)
{
var str = "11-10-10 12:00:00";
DateTime dateTime = DateTime.Parse(str, new CultureInfo("hi-IN", false));
}
}https://stackoverflow.com/questions/4584935
复制相似问题