simpledateformat

Spring Boot (二十九)——使用类型转换器

亡梦爱人 提交于 2020-01-11 19:15:06
类型转换主要用在日期上,前端传来一个日期,后端如何来接收呢? 下面看一个简单的例子: 定义一个接口,方法接收一个Date类型的参数: @RestController public class UserController { @GetMapping ( "/hello" ) public void hello ( Date date ) { System . out . println ( date ) ; } } 前端访问时传入一个date类型的值: 可以看到,日期类型转换异常导致请求失败了,我们可以自定义一个日期的类型转换器来解决这个问题: import org . springframework . core . convert . converter . Converter ; import org . springframework . stereotype . Component ; import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . Date ; @Component public class DateConvert implements Converter < String , Date > {

How to display only “last 24 hours” from a “last 72 hours” JFreeChart TimeSeries

蓝咒 提交于 2020-01-11 10:33:11
问题 I wrote these 2 lines of code to create a chart using an XYDataset : final XYDataset dataset = new TimeSeriesCollection(myInfo.getSeries()); JFreeChart timechart = ChartFactory.createTimeSeriesChart(myInfo.getName() + " CPU (last 72h)", "", "CPU %", dataset, false, false, false); These lines created this nice "last 72h" chart: This is how I added the information to build this chart (this piece of code can run multiple times): SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM

Difference between 'yy' and 'YY' in Java Time Pattern [duplicate]

瘦欲@ 提交于 2020-01-11 09:30:13
问题 This question already has answers here : Y returns 2012 while y returns 2011 in SimpleDateFormat (4 answers) Why does sdf.format(date) converts 2018-12-30 to 2019-12-30 in java? [duplicate] (3 answers) Closed 8 days ago . From document SimpleDateTimePattern, yy should be the same with YY . Today is Dec 30, 2019 , now we get YY for today is 20 , yy for today is 19 . What's the difference between yy and YY in Java Time Pattern? 回答1: yy is the calendar year, while YY is a week year. A week year

Java - SimpleDateFormat parses 12:19:00 to 00:19:00

梦想与她 提交于 2020-01-11 05:42:26
问题 I am trying to parse a string to date, but the output look incorrect: Below is my code. public static void main(String[] args){ Date startDate = new Date(); DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); try { startDate = (Date) formatter.parse("07.10.2012 12:19:24"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Formatted Date " + startDate.toString()); } Program Output: Formatted Date Sun Oct 07 00 :19:24 IST

Parsing string to date: Illegal pattern character 'T'.

我的未来我决定 提交于 2020-01-10 18:48:50
问题 I need to parse a string to date in java. My string has the following format: 2014-09-17T12:00:44.0000000Z but java throws the following exception when trying to parse such format... java.lang.IllegalArgumentException: Illegal pattern character 'T' . Any ideas on how to parse that? Thank you! 回答1: Given your input of 2014-09-17T12:00:44.0000000Z , it is not sufficient to escape the letter T only. You also have to handle the trailing Z . But be aware, this Z is NOT a literal, but has the

Parsing string to date: Illegal pattern character 'T'.

断了今生、忘了曾经 提交于 2020-01-10 18:48:23
问题 I need to parse a string to date in java. My string has the following format: 2014-09-17T12:00:44.0000000Z but java throws the following exception when trying to parse such format... java.lang.IllegalArgumentException: Illegal pattern character 'T' . Any ideas on how to parse that? Thank you! 回答1: Given your input of 2014-09-17T12:00:44.0000000Z , it is not sufficient to escape the letter T only. You also have to handle the trailing Z . But be aware, this Z is NOT a literal, but has the

java.text.ParseException: Unparseable date: “01:19 PM”

最后都变了- 提交于 2020-01-10 05:01:06
问题 I just try to parse a simple time! Here is my code: String s = "01:19 PM"; Date time = null; DateFormat parseFormat = new SimpleDateFormat("hh:mm aa"); try { time = parseFormat.parse(s); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } I am getting this exception: java.text.ParseException: Unparseable date: "01:19 PM" at java.text.DateFormat.parse(Unknown Source) 回答1: This works: public static void main(String[] args) throws Exception { String s = "01:19

How to Parse Date from GMT TimeZone to IST TimeZone and Vice Versa in android

笑着哭i 提交于 2020-01-08 14:35:28
问题 I am working on a project that fetches Date/Time from backend in IST (Indian standard Time) as shown "2013-01-09T19:32:49.103+05:30" . However when i parse it using following DateFormat DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); followed by parsing.. Date date = sdf.parse("2013-01-09T19:32:49.103+05:30"); System.out.println("XYZ ==============>"+date); its Displaying date in GMT format as output i.e Wed Jan 09 14:02:49 GMT+00:00 2013. I have tried it using TimeZone

DateUtils.formatDateRange() issues when formatting date range

风流意气都作罢 提交于 2020-01-07 01:49:56
问题 In my app, I receive dates from a webservice in the form yyyy-MM-dd (e.g. 2016-03-05 ) and I need to format them as [abbreviated month] [date], e.g. Mar 5 . Additionally, I have a start and end date and want to show them as a date range, unless both dates are the same. Currently I'm using DateUtils.formatDateRange(), which should take care of my requirements and provide proper localization, but I'm running into two problems: When my end date is the day after my start date, formatDateRange()

sping MVC 定时任务的设置

泄露秘密 提交于 2020-01-06 21:53:58
  项目中用到了定时任务,写一篇随笔记录一下。   首先在Spring的配置文件ApplicationContext.xml文件的beans标签中添加 xmlns:task="http://www.springframework.org/schema/task" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd   目前我了解的有两种方式使用定时任务:    1.在配置文件中声明定时任务的调用   先在ApplicationContext.xml文件中声明调用的bean <bean id="quartzController" class="com.bizdata.common.socket.web.resource.QuartzTaskController"></bean>   调用的java方法及代码如下 import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.stereotype.Controller; @Controller public class QuartzTaskController {