datetime-conversion

Mapstruct LocalDateTime to Instant

跟風遠走 提交于 2020-01-03 20:59:46
问题 I am new in Mapstruct. I have a model object which includes LocalDateTime type field. DTO includes Instant type field. I want to map LocalDateTime type field to Instant type field. I have TimeZone instance of incoming requests. Manually field setting like that; set( LocalDateTime.ofInstant(x.getStartDate(), timeZone.toZoneId()) ) How can I map these fields using with Mapstruct? 回答1: You have 2 options to achieve what you are looking for. First option: Use the new @Context annotation from 1.2

How to handle MySQL timezone in script

不问归期 提交于 2019-12-31 03:45:29
问题 I am developing a mobile application. From the application calls are made to a web service which runs different queries based on mode (?mode=xx) In some of those queries I use date functions like DATE(NOW()). The data stored in the MySQL database is stored in GMT-7 (Mountain Time Canada). I have yet to register a domain/host for this web service but when I do lets say it is hosted in a different city such as Toronto (which is GMT-5 - 2 hours ahead). Then at 10:05pm Mountain Time Canada a user

yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z' format

佐手、 提交于 2019-12-25 09:39:24
问题 I am trying to convert GMT to IST. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS"); Date c= sdf.parse("2017-03-31T10:38:14.4723017Z"); Date date = new Date(); DateFormat istFormat = new SimpleDateFormat(); DateFormat gmtFormat = new SimpleDateFormat(); TimeZone gmtTime = TimeZone.getTimeZone("GMT"); TimeZone istTime = TimeZone.getTimeZone("IST"); istFormat.setTimeZone(gmtTime); gmtFormat.setTimeZone(istTime); System.out.println("GMT Time: " + istFormat.format(c));

UTC to local time in millis using JodaTime

[亡魂溺海] 提交于 2019-12-23 17:33:09
问题 I am attempting to show transactions over a certain time period using Jodatime. Our server requires a start date and end date to be in UTC (which is probably obvious). Therefore any business logic around these is using DateTime object with the timezone set to DateTimeZone.UTC , e.g. mStartDate = DateTime.now(UTC).withTimeAtStartOfDay(); That works well except when it comes to display the time I don't know how to augment it for the local (system default) timezone. Ideally I would like to use

Convert between arbitrary timezones

佐手、 提交于 2019-12-22 09:55:18
问题 I'm trying to find a simple yet robust way to convert time between arbitrary time zones. UPDATE 1: I don't understand why this has been downvoted. I've made my research and explored the possibilities. This problem is not as trivial as it might seem. If you think that the function shall look like bTime = aTime + 3 , then please reconsider. Timezones and DSTs are in a state of constant flux. Read this for reference: list of pending / proposed timezone changes. Note that some countries are

Convert 24 Hour Time in to 12 Hour Time in Java

馋奶兔 提交于 2019-12-20 03:56:09
问题 I want to convert 24 Hour time into 12 Hour AM/PM time. e.g:- How to convert date 2012-03-20T22:30:00.000+05:30 to to 2012-03-20 10:30 PM?? I have extratced the date but its in 24 Hour time. I though used SimpleDateFormater but still for 12.30 it is showing 00.30 and not 12.30 PM . Thanks in advance. 回答1: The bundled java.util.Date and .Calendar classes are notoriously troublesome. Avoid them. Use either Joda-Time or the new java.time package in Java 8. Joda-Time DateTimeZone timeZone =

pandas convert from datetime to integer timestamp

為{幸葍}努か 提交于 2019-12-19 19:44:12
问题 Considering a pandas dataframe in python having a column named time of type integer, I can convert it to a datetime format with the following instruction. df['time'] = pandas.to_datetime(df['time'], unit='s') so now the column has entries like: 2019-01-15 13:25:43 . What is the command to revert the string to an integer timestamp value (representing the number of seconds elapsed from 1970-01-01 00:00:00 )? I checked pandas.Timestamp but could not find a conversion utility and I was not able

How to convert from UTC to local time in C?

与世无争的帅哥 提交于 2019-12-17 16:13:28
问题 It's a simple question, but the solution appears to be far from simple. I would like to know how to convert from UTC to local time. I am looking for a solution in C that's standard and more or less guaranteed to work on any computer at any location. I have read the following links carefully but I can't find a solution there: Converting string containing localtime into UTC in C Converting Between Local Times and GMT/UTC in C/C++ I have tried a number of variations, such as (datetime is a

LocalDateTime to java.sql.Date in java 8?

泄露秘密 提交于 2019-12-17 11:43:23
问题 How to convert LocalDateTime to java.sql.Date in java-8? My search on internet mostly give me Timestamp related code or LocalDate to java.sql.Date . I'm looking for LocalDateTime to java.sql.Date . 回答1: There is no direct correlation between LocalDateTime and java.sql.Date , since former is-a timestamp, and latter is-a Date. There is, however, a relation between LocalDate and java.sql.Date , and conversion can be done like this: LocalDate date = //your local date java.sql.Date sqlDate = java

How to convert a long to a Date with “dd/MM/yyyy” format [duplicate]

最后都变了- 提交于 2019-12-14 03:29:47
问题 This question already has answers here : Converting long (whose decimal representation represents a yyyyMMdd.. date) to a different date format (2 answers) Closed last year . I have a variable of type Long. Long longDate = 20180201110400 It represents this: 2018/02/01 11:04:00 I want to convert the format and variable type like below: Format should be "dd/MM/yyyy" and type should be Date . How can I do that? 回答1: You can covert the long to a Date object first then you can further convert it