date

Convert day of week number to weekday name in R

痴心易碎 提交于 2021-02-07 20:10:57
问题 I have a column in a dataframe that contains the day number ( 0 through 6, 0=Sunday, 1=Monday, etc) and I need to convert that to the day name. How can I do this? Sample data: df <- data.frame(day_number=0:6) 回答1: Simple way with dplyr. library(dplyr) df <- data.frame(day_number=0:6) df$day_number <- recode(df$day_number, "0"="Sunday", "1"="Monday", "2"="Tuesday", "3"="Wednesday", "4"="Thursday", "5"="Friday", "6"="Saturday") 回答2: Treat the column as a factor with day name as label: x <- data

Convert day of week number to weekday name in R

孤人 提交于 2021-02-07 20:08:26
问题 I have a column in a dataframe that contains the day number ( 0 through 6, 0=Sunday, 1=Monday, etc) and I need to convert that to the day name. How can I do this? Sample data: df <- data.frame(day_number=0:6) 回答1: Simple way with dplyr. library(dplyr) df <- data.frame(day_number=0:6) df$day_number <- recode(df$day_number, "0"="Sunday", "1"="Monday", "2"="Tuesday", "3"="Wednesday", "4"="Thursday", "5"="Friday", "6"="Saturday") 回答2: Treat the column as a factor with day name as label: x <- data

Getting Date Time in Unix Time as Byte Array which size is 4 bytes with Java

◇◆丶佛笑我妖孽 提交于 2021-02-07 19:53:34
问题 How Can I get the date time in unix time as byte array which should fill 4 bytes space in Java? Something like that: byte[] productionDate = new byte[] { (byte) 0xC8, (byte) 0x34, (byte) 0x94, 0x54 }; 回答1: First: Unix time is a number of seconds since 01-01-1970 00:00:00 UTC. Java's System.currentTimeMillis() returns milliseconds since 01-01-1970 00:00:00 UTC. So you will have to divide by 1000 to get Unix time: int unixTime = (int)(System.currentTimeMillis() / 1000); Then you'll have to get

Getting Date Time in Unix Time as Byte Array which size is 4 bytes with Java

青春壹個敷衍的年華 提交于 2021-02-07 19:50:59
问题 How Can I get the date time in unix time as byte array which should fill 4 bytes space in Java? Something like that: byte[] productionDate = new byte[] { (byte) 0xC8, (byte) 0x34, (byte) 0x94, 0x54 }; 回答1: First: Unix time is a number of seconds since 01-01-1970 00:00:00 UTC. Java's System.currentTimeMillis() returns milliseconds since 01-01-1970 00:00:00 UTC. So you will have to divide by 1000 to get Unix time: int unixTime = (int)(System.currentTimeMillis() / 1000); Then you'll have to get

Conversion of date format %B %Y

妖精的绣舞 提交于 2021-02-07 17:10:35
问题 Can we somehow convert dates such as "November 2017", "December 2017" to date? I tried to import csv data, but received factor columns. I tried the following code, but was not successful. as.POSIXct(as.character(dat$Date), format = "%B %Y") 回答1: A quick solution from lubridate package dmy(paste("01", dat$Date)) 回答2: A POSIXct date needs the day of the month to be complete and valid. You can add it to the date strings, then use the format "%B %Y %d" e.g. : as.POSIXct(paste(as.character(dat

Calculate day of month with month, year, day of week and number of week

妖精的绣舞 提交于 2021-02-07 16:41:47
问题 How can I calculate the day of month in PHP with giving month, year, day of week and number of week. Like, if I have September 2013 and day of week is Friday and number of week is 2, I should get 6. (9/6/2013 is Friday on the 2nd week.) 回答1: One way to achieve this is using relative formats for strtotime(). Unfortunately, it's not as straightforward as: strtotime('Friday of second week of September 2013'); In order for the weeks to work as you mentioned, you need to call strtotime() again

Calculate day of month with month, year, day of week and number of week

我与影子孤独终老i 提交于 2021-02-07 16:39:22
问题 How can I calculate the day of month in PHP with giving month, year, day of week and number of week. Like, if I have September 2013 and day of week is Friday and number of week is 2, I should get 6. (9/6/2013 is Friday on the 2nd week.) 回答1: One way to achieve this is using relative formats for strtotime(). Unfortunately, it's not as straightforward as: strtotime('Friday of second week of September 2013'); In order for the weeks to work as you mentioned, you need to call strtotime() again

How do I parse “YYYY-MM-DD” with joda time

只谈情不闲聊 提交于 2021-02-07 14:29:15
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.

How do I parse “YYYY-MM-DD” with joda time

ぃ、小莉子 提交于 2021-02-07 14:27:34
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.

How do I parse “YYYY-MM-DD” with joda time

你。 提交于 2021-02-07 14:27:24
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.