datetime-conversion

Converting a time decimal/fraction representing days to its actual time in R? [duplicate]

淺唱寂寞╮ 提交于 2019-11-28 10:16:53
问题 This question already has an answer here: Convert a decimal number to HH:MM 3 answers I have a column in R on my dataset with values that have been converted into what I believe is a time decimal fraction based on days . I have been using this site as a reference: http://www.calculatorsoup.com/calculators/time/decimal-to-time-calculator.php Which converting 0.3408565 days corresponds to the time of 8:10:50 by doing the following: 0.3408565 * 24 hours/day = 8.180555544 = 8 hours 0.180555544 *

LocalDateTime to java.sql.Date in java 8?

流过昼夜 提交于 2019-11-28 09:11:17
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 . 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.sql.Date.valueOf(date) Which for any given LocalDateTime gives you the following code: LocalDateTime

How to convert ZonedDateTime to Date?

只愿长相守 提交于 2019-11-28 03:45:22
I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver for Java understands only the Date type. So assuming that in my code I am using the new Java 8 ZonedDateTime to get the UTC now ( ZonedDateTime.now(ZoneOffset.UTC) ), how can I convert this ZonedDateTime instance to the "legacy" Date class? Slim Soltani Dridi You can convert ZonedDateTime to an instant, which you can use directly with Date. Date.from(java.time.ZonedDateTime.now().toInstant()); tl;dr java.util.Date.from( //

How to convert from UTC to local time in C?

时间秒杀一切 提交于 2019-11-27 21:35:09
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 string with time and date in UTC): strptime(datetime, "%A %B %d %Y %H %M %S", tp); strftime(printtime,

How to convert ZonedDateTime to Date?

三世轮回 提交于 2019-11-27 00:05:10
问题 I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver for Java understands only the Date type. So assuming that in my code I am using the new Java 8 ZonedDateTime to get the UTC now ( ZonedDateTime.now(ZoneOffset.UTC) ), how can I convert this ZonedDateTime instance to the "legacy" Date class? 回答1: You can convert ZonedDateTime to an instant, which you can use directly with

Convert DateTime for MySQL using C#

为君一笑 提交于 2019-11-26 22:14:27
I want to change the DateTime for MySQL in C#. My MySQL database only accept this format 1976-04-09 22:10:00 . In C# have a string who have a date value: string str = "12-Apr-1976 22:10"; I want to convert for MySQL then it look like: 1976-04-12 22:10 How I can change them or how other programmer do this by using dd mm hh yy method? Can anyone tell me about them? Keep in mind that you can hard-code ISO format string formatForMySql = dateValue.ToString("yyyy-MM-dd HH:mm:ss"); or use next: // just to shorten the code var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat; // "1976

Compare DATETIME and DATE ignoring time portion

橙三吉。 提交于 2019-11-26 18:42:27
I have two tables where column [date] is type of DATETIME2(0) . I have to compare two records only by theirs Date parts (day+month+year), discarding Time parts (hours+minutes+seconds). How can I do that? Use the CAST to the new DATE data type in SQL Server 2008 to compare just the date portion: IF CAST(DateField1 AS DATE) = CAST(DateField2 AS DATE) A small drawback in Marc's answer is that both datefields have been typecast, meaning you'll be unable to leverage any indexes. So, if there is a need to write a query that can benefit from an index on a date field, then the following (rather

Convert DateTime for MySQL using C#

旧城冷巷雨未停 提交于 2019-11-26 07:34:15
问题 I want to change the DateTime for MySQL in C#. My MySQL database only accept this format 1976-04-09 22:10:00 . In C# have a string who have a date value: string str = \"12-Apr-1976 22:10\"; I want to convert for MySQL then it look like: 1976-04-12 22:10 How I can change them or how other programmer do this by using dd mm hh yy method? Can anyone tell me about them? 回答1: Keep in mind that you can hard-code ISO format string formatForMySql = dateValue.ToString("yyyy-MM-dd HH:mm:ss"); or use

Compare DATETIME and DATE ignoring time portion

时间秒杀一切 提交于 2019-11-26 06:31:52
问题 I have two tables where column [date] is type of DATETIME2(0) . I have to compare two records only by theirs Date parts (day+month+year), discarding Time parts (hours+minutes+seconds). How can I do that? 回答1: Use the CAST to the new DATE data type in SQL Server 2008 to compare just the date portion: IF CAST(DateField1 AS DATE) = CAST(DateField2 AS DATE) 回答2: A small drawback in Marc's answer is that both datefields have been typecast, meaning you'll be unable to leverage any indexes. So, if