您好我想将当前日期转换为此格式YYYY-MM-DD.但是,它会将日期转换为String格式,但我想将其转换回Date格式.所以有人可以就此提出建议吗?
到目前为止这是我的代码
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String datestring = dateFormat.format(date);
Run Code Online (Sandbox Code Playgroud) 我的字符串值为08:03:10 pm,我想把它转换成时间.我怎么能用Java做到这一点?
java.util.date的默认格式是这样的"Mon May 27 11:46:15 IST 2013".如何将其转换为时间戳并以秒计算相同和当前时间之间的差异?
java.util.Date date= new java.util.Date();
Timestamp ts_now = new Timestamp(date.getTime());
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了当前的时间戳.但是,我不知道如何找到上述字符串的时间戳.
我是Play Framework的新手.我可以通过请求直接发送简单的数据类型,如字符串,整数等,并在后端Java方法中访问它们.
当我尝试在路径文件中执行此操作时,
GET /food/fetchMealInfo/:noOfDays/:dateSelected controllers.trackandplan.FoodController.fetchMealInfo(noOfDays : Integer, dateSelected : Date)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误说
Compilation error
not found: type Date
Run Code Online (Sandbox Code Playgroud)
将日期对象从前端AngularJS应用程序传输到Play Framework中的Java应用程序是什么是正确,安全和干净的方法.请指导.
我有字符串
"11-04-2015 22:01:13:053" or "32476347656435"
Run Code Online (Sandbox Code Playgroud)
如何检查字符串是否为日期?
使用正则表达式检查字符串是否为数字
String regex = "[0-9]+";
Run Code Online (Sandbox Code Playgroud) 可能重复:
计算Java中日期的差异如何在Java中
减去日期?
我正在从字符串解析两个日期,如下所示:
Oct 15, 2012 1:07:13 PM
Oct 23, 2012 03:43:34 PM
Run Code Online (Sandbox Code Playgroud)
我需要做的是找到这两个日期之间的区别,例如:
Oct 23, 2012 03:43:34 PM - Oct 15, 2012 1:07:13 PM
Run Code Online (Sandbox Code Playgroud)
= 8天2小时36分21秒
^这是我需要得到的两个日期/时间
我相信我需要解析格式并将其转换为另一种格式,然后减去它们之间的差异并进行数学运算以获得两者之间的天/小时/分钟/秒
string : 2014-04-25 17:03:13
Run Code Online (Sandbox Code Playgroud)
使用SimpleDateFormat是否足以格式化?否则我将转向任何新的API?
Date date = new Date(string);
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
out.println( dateFormat.format (date));
Run Code Online (Sandbox Code Playgroud)
我的预期结果是(印度地区):
Date : 25-04-2014
Time : 05:03 PM
Run Code Online (Sandbox Code Playgroud) 我目前正致力于将日期转换为字符串.之后我将该字符串转换为datetime.但它错了.有人可以帮帮我吗?
这是代码.
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
SimpleDateFormat outFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String dt1 = outFormat.format(date1);
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
DateTime dt = formatter.parseDateTime(dt1);
Run Code Online (Sandbox Code Playgroud) 我是Java新手.我在数据库中从数据库中检索我的第一列,表示数据为:
2014-09-01 10:00:00.000
Run Code Online (Sandbox Code Playgroud)
现在我想只显示时间:
10:00:00
Run Code Online (Sandbox Code Playgroud)
怎么做?我检索我的列的代码是:
public String[] getChartTime() throws SQLException {
List < String > timeStr = new ArrayList < String > ();
String atime[] = null;
getConnection();
try {
con = getConnection();
String sql = "exec vcs_gauge @gauge_name=?,@first_rec_time=?,@last_rec_time=?";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("date is " + df.format(currentDate));
clstmt = con.prepareCall(sql);
clstmt.setString(1, "vs3_bag");
clstmt.setString(2, "2014-09-01 10:00:00");
clstmt.setString(3, "2014-09-01 11:00:00");
clstmt.execute();
rs = clstmt.getResultSet();
while (rs.next()) {
// Just get the value of the column, and add it …Run Code Online (Sandbox Code Playgroud)我试图解析ZonedDateTime从s Strings的格式如下:
2017-08-10 16:48:37 -0500
我之前使用Jodatime成功完成了这项工作DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss Z").
我试图用Java Time API替换Jodatime,并且相同的模式不再有效.
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss Z");
ZonedDateTime.parse("2017-08-10 16:48:37 -0500", dtf);
Run Code Online (Sandbox Code Playgroud)
导致以下异常:
java.time.format.DateTimeParseException: Text '2017-08-10 16:48:37 -0500' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {DayOfMonth=10, OffsetSeconds=-18000, WeekBasedYear[WeekFields[SUNDAY,1]]=2017, MonthOfYear=8},ISO resolved to 16:48:37 of type java.time.format.Parsed
Run Code Online (Sandbox Code Playgroud)
在Java Time API中使用格式字符串的正确模式是什么?