我需要在java中比较两个字符串日期:
String date1 = "2017-05-02";
String date2 = "5/2/2017";
//formatter for the first date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
Date formattedDate1 = formatter.parse(date1);
//formatter for the second date
formatter = new SimpleDateFormat("m/d/yyyy");
Date formattedDate2 = formatter.parse(date2);
//Wrong results
String formatted1 = formattedDate1.toString(); //Mon Jan 02 00:05:00 EET 2017
String formatted2 = formattedDate2.toString(); //Mon Jan 02 00:05:00 EET 2017
Run Code Online (Sandbox Code Playgroud)
实际上,如果我比较那些2我可能会得到'真'但我的日期不是1月,它是'2017年5月5日'.
另一个问题是我不能使用Date对象,我需要将"2017-05-02"转换为"2017/2/15",然后将其传递给另一个函数
我面临着一些问题解析日期格式dd-m-y与SimpleDateFormat类在Java中.
那么这个日期格式类型(12-oct-14)有任何日期格式化程序吗?
我需要从a获取日期String,格式如下:uuuu-MM-dd HH:mm
输入具有该格式,我希望我的日期格式相同(年 - 月 - 日小时:分钟).当我这样做时:
LocalDate aux = LocalDate.parse(times.get(index),DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm "));
Run Code Online (Sandbox Code Playgroud)
有了这个输入:2017-12-05 20:16
我只得到这个:2017-12-05
我不知道为什么,我尝试了很多格式,总是丢失时间和分钟.任何的想法?
在 C# 中将字符串 (dd/MM/yyyy) 转换为日期 (MM-dd-YYYY) 的最佳方法是什么?
string date = "15/01/2017";
DateTime date1 = DateTime.Parse(date, new CultureInfo("en-CA"));
btnBack.Text = date1.ToString();
Run Code Online (Sandbox Code Playgroud)
我有错误
字符串未被识别为有效的日期时间。