unix-timestamp

Given a Unix timestamp, how to get beginning and end of that day?

萝らか妹 提交于 2020-04-05 07:11:50
问题 I have a Unix timestamp like this: $timestamp=1330581600 How do I get the beginning of the day and the end of the day for that timestamp? e.g. $beginOfDay = Start of Timestamp's Day $endOfDay = End of Timestamp's Day I tried this: $endOfDay = $timestamp + (60 * 60 * 23); But I don't think it'll work because the timestamp itself isn't the exact beginning of the day. 回答1: strtotime can be used to to quickly chop off the hour/minutes/seconds $beginOfDay = strtotime("today", $timestamp);

How can we get weekday based on given date in unix

痴心易碎 提交于 2020-03-18 17:54:16
问题 From a given date in %m-%d-%Y format we should determine what day it is Please help me with the command like if i pass a date like 09-01-2017 output should be Friday 回答1: DayOfWeek=$(date +%A) This would yield the day of week monday-sunday If your input date is strictly in the format MM-DD-YYYY , use the following IFS='-' read -ra ADDR <<< "09-01-2017" formattedDate=${ADDR[2]}-${ADDR[0]}-${ADDR[1]} date -d $formattedDate +%A The first line tokenizes the components of the date and the second

How can we get weekday based on given date in unix

岁酱吖の 提交于 2020-03-18 17:53:17
问题 From a given date in %m-%d-%Y format we should determine what day it is Please help me with the command like if i pass a date like 09-01-2017 output should be Friday 回答1: DayOfWeek=$(date +%A) This would yield the day of week monday-sunday If your input date is strictly in the format MM-DD-YYYY , use the following IFS='-' read -ra ADDR <<< "09-01-2017" formattedDate=${ADDR[2]}-${ADDR[0]}-${ADDR[1]} date -d $formattedDate +%A The first line tokenizes the components of the date and the second

Convert unix timestamp column to day of week in R

让人想犯罪 __ 提交于 2020-02-21 03:00:59
问题 I am working with a data frame in R labeled "mydata". The first column, labled "ts" contains unix timestamp fields. I'd like to convert these fields to days of the week. I've tried using strptime and POSIXct functions but I'm not sure how to execute them properly: > strptime(ts, "%w") --Returned this error: "Error in as.character(x) : cannot coerce type 'closure' to vector of type 'character'" I also just tried just converting it to human-readable format with POSIXct: as.Date(as.POSIXct(ts,

What does the 'Z' mean in Unix timestamp '120314170138Z'?

百般思念 提交于 2020-02-09 06:30:46
问题 I have an X.509 certificate which has the following 2 timestamps: ['validFrom'] = String(13) "120314165227Z" ['validTo'] = String(13) "130314165227Z" What does the postfix character 'Z' mean. Does it specify the timezone? 回答1: Yes. 'Z' stands for Zulu time, which is also GMT and UTC. From http://en.wikipedia.org/wiki/Coordinated_Universal_Time: The UTC time zone is sometimes denoted by the letter Z—a reference to the equivalent nautical time zone (GMT), which has been denoted by a Z since

How do i get last sunday date from a given date in unix

限于喜欢 提交于 2020-01-30 08:02:44
问题 get last sunday date as output from a given date (not current date) as input Example input: 08-30-2017 (%m-%d-%Y) output should be last sunday: 08-27-2017 === All of the below commands use current day as reference .But i want to give the reference date as input to get last sunday. Please help me with the command. date +%m-%d-%Y -d "2017-09-10 -7 days" date +%m-%d-%Y -d "last Sun" 回答1: If you deal with a fixed date format %m-%d-%Y , it should be transformed to %Y-%m-%d format to be processed

How to generate a range of nonweekend dates using tools available in bash?

左心房为你撑大大i 提交于 2020-01-24 17:52:05
问题 I want to generate a list of files where the name consists of ${filename}.${date} , for example file.20111101 , file.20120703 , starting November 1, 2011 until today and it should exclude weekends. Thanks. 回答1: try this for 2011 for y in 2011; do for m in {1..12}; do for d in `cal -m $m $y|tail -n +3|cut -c 1-15`; do printf "file.%04d%02d%02d\n" $y $m $d; done; done; done or this for NOV-2011 to DEC-2013 for ym in {2011' '{11,12},{2012..2013}' '{1..12}}; do read y m <<<$ym; for d in `cal -m

Can iOS boot time drift?

坚强是说给别人听的谎言 提交于 2020-01-24 10:45:16
问题 I'm using this code to determine when my iOS device last rebooted: int mib[MIB_SIZE]; size_t size; struct timeval boottime; mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; size = sizeof(boottime); if (sysctl(mib, MIB_SIZE, &boottime, &size, NULL, 0) != -1) { return boottime.tv_sec; } return 0; I'm seeing some anomalies with this time. In particular, I save the long and days and weeks later check the saved long agains the value returned by the above code. I'm not sure, but I think I'm seeing some

Why does MySQL unix time stop short of the 32 bit unsigned integer limit?

半城伤御伤魂 提交于 2020-01-21 11:17:06
问题 mysql> SELECT FROM_UNIXTIME(2145916799), FROM_UNIXTIME(2145916800), POW(2,32-1)-1, 2145916799 - POW(2,32-1)-1; +---------------------------+---------------------------+---------------+----------------------------+ | FROM_UNIXTIME(2145916799) | FROM_UNIXTIME(2145916800) | POW(2,32-1)-1 | 2145916799 - POW(2,32-1)-1 | +---------------------------+---------------------------+---------------+----------------------------+ | 2037-12-31 18:59:59 | NULL | 2147483647 | -1566850 | +---------------------

Convert MySQL UTC datetime to UNIX timestamp

瘦欲@ 提交于 2020-01-17 04:48:08
问题 These both correctly return the current UNIX timestamp: SELECT UNIX_TIMESTAMP(LOCALTIMESTAMP()); #MySql echo time(); //PHP But I'm storing UTC_TIMESTAMPs in my database (not LOCALTIMESTAMPs). How can I convert a UTC datetime to a UNIX timestamp using MySQL? 回答1: Note that LOCALTIMESTAMP() is a synonym for NOW(). So what you're really asking is how to get the current time and convert it to GMT and then convert to a unix timestamp to store in the db. So this will work: SELECT UNIX_TIMESTAMP