datetime-conversion

Java Date and utcTimeOffset [closed]

穿精又带淫゛_ 提交于 2019-12-13 10:13:45
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . I have a Java Date ( java.util.Date ) - Tue Jul 31 00:53:43 CEST 2018 and a utcTimeOffset = +0200, which says that give, date is +2 hours from UTC. This is a legacy code and Java 8 is not an option. What I am getting is text representation of date as 20180730131847 and utcTimeOffset = +0200 from a

Conversion of varchar into Datetime

早过忘川 提交于 2019-12-13 03:30:36
问题 Why does the following code work: CAST(DateOfAction AS Date) but this code does not: CAST(DateOfAction AS Datetime) note: DateOfAction is a varchar field Can someone explain this and give the right code? 回答1: Possibly because your VARCHAR field contains a value that might convert to a DATE (no time values), but isn't in any of the valid supported formats that SQL Server CAST and CONVERT support. Since you didn't provide any samples of what your data looks like, we can only guess..... Check

18 digit timestamp to Local Time

青春壹個敷衍的年華 提交于 2019-12-12 06:37:27
问题 I came across Sq-lite database.I found our date time is stored in 18 digit time-stamp. Please help me how to convert it to Local Time. (I tried to convert it(No.of milliseconds from 1900). But i did not get it.It shows 29 days difference. I added 29 days of milliseconds to time. But time output is wrong.My assumption is, it will be NTP time.) Here i give 18-digit time-stamp and its equivalent date time. Time-Stamp Date-Time 362087070028927400 27-10-2014 15:06:57 362087302762879170 27-10-2014

Convert 64-bit Hex to nanoseconds timestamps

早过忘川 提交于 2019-12-12 02:52:49
问题 I have timestamps that are represented in 64-bit hex. Is there a way to convert it to nanosecond timestamps? (preferably in c++) 回答1: Found it! I used std::hex to convert a hex value to long, which in turn gives me the nanosecond precision. 来源: https://stackoverflow.com/questions/36731370/convert-64-bit-hex-to-nanoseconds-timestamps

converting epoch to ZonedDateTime in Java

可紊 提交于 2019-12-11 02:05:31
问题 How to convert epoch like 1413225446.92000 to ZonedDateTime in java? The code given expects long value hence this will throw NumberFormatException for the value given above. ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(dateInMillis)), ZoneId.of(TIME_ZONE_PST)); 回答1: Basil Bourque’s answer is a good one. Taking out the nanoseconds from the fractional part into an integer for nanoseconds may entail a pitfall or two. I suggest: String dateInMillis = "1413225446.92000"; String[]

Get Human readable time from nanoseconds

时间秒杀一切 提交于 2019-12-10 16:59:14
问题 I am trying to implement an ETA feature Using System.nanoTime() startTime = System.nanoTime() Long elapsedTime = System.nanoTime() - startTime; Long allTimeForDownloading = (elapsedTime * allBytes / downloadedBytes); Long remainingTime = allTimeForDownloading - elapsedTime; But I cannot figure how to get a human readable form of the nanoseconds; for example: 1d 1h , 36s and 3m 50s . How can I do this? 回答1: If remainingTime is in nanoseconds , just do the math and append the values to a

java.time.format.DateTimeParseException: Text '09/10/2019' could not be parsed at index 0 could not be parsed, unparsed text found at index 19

大城市里の小女人 提交于 2019-12-10 12:27:17
问题 I am developing news app and I have converted elapsed time from now to that date but when I run code I am getting following exception in my adapter class java.time.format.DateTimeParseException: Text '09/10/2019' could not be parsed at index 0 could not be parsed, unparsed text found at index 19 below my Adapter class @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") class TopHeadlinesAdapter(val context: Context) : RecyclerView.Adapter<TopHeadlinesAdapter.MyViewHolder>() { var

Java 8 timezone conversion

丶灬走出姿态 提交于 2019-12-10 11:13:38
问题 I know there are similar questions like this, but I wasn't quite able to find the example similar to mine. I learned about LocalDateTime and ZonedDateTime but I don't know how to tell my ZonedDateTime what's assumed timezone of parsed date. I'm migrating from Java 7 to Java 8. In my code, I have a method like this: public String changeTZ(String tzFrom, String tzTo, String dateToChange) { ZoneId zoneFrom = ZoneId.of(tzFrom); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat

Conversion error when converting 'nvarchar' to 'datetime' in sql server

余生颓废 提交于 2019-12-08 11:35:34
问题 I have this code : DECLARE @StartDate nvarchar SET @StartDate='22/10/2014' SELECT CAST (@StartDate as datetime) And it gives me this error: Conversion failed when converting date and/or time from character string. Can anyone suggest a better way/at least no error way to do this. 回答1: To convert the string which represents to date in format dd/mm/yyyy you can use this: DECLARE @StartDate nvarchar(10) SET @StartDate='22/10/2014' SELECT CONVERT(datetime, @StartDate, 103) Declaring varchar means

Convert between arbitrary timezones

心已入冬 提交于 2019-12-06 00:30:59
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 actually changing their timezones , not just DST settings! And Brazil changed the date on which they change