If all I have is the unix timestamp and I am not able to use any functions to format it (such as day of the week or date) is there any known pattern by looking at the timestamp to deduce what day of the week it is?
for example perhaps all timestamps that are divisible by 150 are Mondays
The Unix Epoch (Jan 1, 1970, 00:00) was on a Thursday. Specifically it marked the beginning of a Thursday.
The first Monday after the Unix Epoch begins on Jan 5, 1970, 00:00. This is a UNIX timestamp of 96 hours.
The second Monday after the Unix Epoch begins on Jan 12, 1970, 00:00. This is a UNIX timestamp of 264 hours.
Let's assume X is your Unix timestamp in hours. The formula ((X - 96) % (264 - 96)) / 24 will return a zero-based weekday index where 0 is Monday and 6 is Sunday. The formula looks like this:
(X - 96) % 168 / 24 (if X is your timestamp in hours)
(X - 345600) % 604800 / 86400 (if X is your timestamp in seconds)
(X - 345600000) % 604800000 / 86400000 (if X is your timestamp in milliseconds)
If i experiment with exactly this moment, defined by a Unix timestamp of 1466710873523 ms i would get (1466710873523 - 345600000) % 604800000 / 86400000 which is ~3.8 (meaning it's Thursday) (almost Friday though :). Note though that it's Thursday UTC - in certain timezones it might be different so for local time you would need to take timezone offset into account.
From my own observations, the timestamp at midnight GMT ends in 000 every 6 days. The sequence is as follows: 000, 400, 800, 200, 600, 000, 400, 800, 200...
So, today (in UCT) started at 1465948800 and has been Wednesday.
So I know that that tomorrow's starting timestamp will end with 200 etc.
If you count the days from today (1465948800) to your desired date and divide by 6,
if the remainder is 1, the ending will be '200',
2: '600',
3: '000',
4: '400',
5: '800'.
Because a week has 7 days, if this Wednesday ended in 800, next Wednesday will end in 200 and the following wednesday in 600, etc.
Related
I'm trying to covert dates like 09:00 AM into 24 hours it works perfect with the intl package but I'm getting only one issue that the date 12:00 PM it convert it to 00:00 and 12:00 AM it convert it to 12:00 otherwise all other dates works perfect.
print(DateFormat.Hm()
.format(DateFormat("HH:mm a").parse('12:00 PM'))); // doesn't work => it prints 00:00
print(DateFormat.Hm()
.format(DateFormat("HH:mm a").parse('12:00 AM'))); // doesn't work it prints 12:00
print(DateFormat.Hm()
.format(DateFormat("HH:mm a").parse('09:00 PM')));// works => 21:00
use h instead of H
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
https://api.flutter.dev/flutter/intl/DateFormat-class.html
print(DateFormat.Hm()
.format(DateFormat("hh:mm a").parse('12:00 PM')));
print(DateFormat.Hm()
.format(DateFormat("hh:mm a").parse('12:00 AM')));
print(DateFormat.Hm()
.format(DateFormat("hh:mm a").parse('09:00 PM')));
I have a matrix that has 3months of data or so..Its a 952x1 matrix with the elements in the following format(3 hourly )
Aug-05-2015 03:00:00
Aug-05-2015 06:00:00
Aug-05-2015 09:00:00
Aug-05-2015 12:00:00
Aug-05-2015 15:00:00
Aug-05-2015 18:00:00
Aug-05-2015 21:00:00
Aug-06-2015 00:00:00
Aug-06-2015 03:00:00
Aug-06-2015 06:00:00
I would want to choose say only day timings/ only night or say for august month alone. How do i do that.
Further to my question, if I have a group of .wav files and Im trying to pick only month wise or do daily psd averages etc or chose files belonging to a month how to go about? The following are first 10 .wav files in a .txt file that are read into matlab code-
AMAR168.1.20150823T200235Z.wav
AMAR168.1.20150823T201040Z.wav
AMAR168.1.20150823T201845Z.wav
AMAR168.1.20150823T202650Z.wav
AMAR168.1.20150823T203455Z.wav
AMAR168.1.20150823T204300Z.wav
AMAR168.1.20150823T205105Z.wav
AMAR168.1.20150823T205910Z.wav
AMAR168.1.20150823T210715Z.wav
yyyymmddTHHMMSSZ.wav is part of the format to get sense of some parameters.
Thanks.
Are these datetimes? If so, you can use logical indexing here if you make use of some of the datetime functions. To get the times in August:
t = datetime(2015, 8, 1, 3, 0, 0) + hours(3:3:3000)';
t(month(t) == 8) % Times in August
To get the times that are during the day or night:
t(hour(t) < 12) % Day times
t(hour(t) >= 12) % Night times
I have to open some logs that have a date in the filename. So I am trying to open all the files through a certain date.
I'm using DateTime. I do:
do
{
$datechoice = $today->strftime('%G%m%d'); #YearMonthDay
$date_for_graph = $today->strftime('%d/%m/%G');
# unshift #Log_Period_Time, "$date_for_graph";
print $datechoice." - ".$date_for_graph."<br>";
$today->subtract(days => 1);
} while($datechoice > 20141107);
But the output shows the wrong year for dates near the end of a year:
20160109 - 09/01/2016
20160108 - 08/01/2016
20160107 - 07/01/2016
20160106 - 06/01/2016
20160105 - 05/01/2016
20160104 - 04/01/2016
20150103 - 03/01/2015 <-- Should be 2016
20150102 - 02/01/2015
20150101 - 01/01/2015
20151231 - 31/12/2015
20151230 - 30/12/2015
20151229 - 29/12/2015
...
20150103 - 03/01/2015
20150102 - 02/01/2015
20150101 - 01/01/2015
20151231 - 31/12/2015
20151230 - 30/12/2015
20151229 - 29/12/2015
20141228 - 28/12/2014 <-- Should be 2015
20141227 - 27/12/2014
20141226 - 26/12/2014
Why is this happening?
Use %Y, not %G, unless you specifically mean to display the date according to the ISO 8601 week number calendar.
(In the ISO calendar, every year is a whole number of weeks running Monday-Sunday. So whenever January 1st isn't a Monday there will be up to three days on one side of it that fall in the "wrong" year by ISO reckoning. For instance, ISO year 2021 started on Monday, January 4th; January 1st through 3rd fell in the last week of 2020. Going the other way, ISO year 2026 will start on Monday, December 29th, 2025, so the last 3 days of that December are already the first week of the next ISO year.)
I have a 1437x159x1253 large matrix (let's call it A) of daily sea ice data for a little over 2 years. I need to write a code that takes the daily data from each month and does mean(A, 3) on it. So basically, 1253 is the t in days. If I start from January, I need to do mean(A,3) of the first 31 days, then the mean(A,3) of February, the next 28 or 29 days. Because the days alternate between 31 and 30 (and 28 or 29 for February), I don't know how to write a code to do this. I can do it manually, but that would take a while.
Thanks!
You can initialize an array containing the number of days in each month, Mon = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] using boolean to check whether it's a leap year (to set Mon(2) = 29). The number of days will help you index each month appropriately, using a loop like:
index=1;
for i=1:12
average = mean(A(:,:,index:(index+Mon(i)-1),3);
index = index+M(i); % Starting location of the next month
end
Why does get-date & [datetime]::FromFileTime returns different values when converting FileTime? An example:
Get-Date 129442497539436142
returns Thursday, March 10, 0411 4:55:53 PM, but
[datetime]::FromFileTime("129442497539436142")
returns Thursday, March 10, 2011 11:55:53 AM
They produce the same result for me, presumably because I'm in GMT.
(FromFileTime parses the time as UTC, Get-Date appears to be using your local time.)
FileTimes are so-called Ticks. 10 million pass every second. Filetime are 0 at midnight, January 1st 1601 (UTC).
Get-date also have ticks, but the base of ticks used by Get-Date is NOT 1601.
It is January 1st year 1.
You can basically identify the 2 different types of ticks by the first digit.
Filetime ticks starts with digit 1 in the rough range of -100 to + 200 years from now.
The ticks using base on January 1st year 0 starts with 6 in roughly the same time range...
In PowerShell you can get verify Jan. 1st year 1 is tick 0 by typing:
[datetime]'0001-01-01' | Select-Object -property Ticks
Get-Date get ticks from 01/01/0001 00:00
[datetime]::FromFileTimeUTC($a) get ticks from 01/01/1601 00:00
You wrote:
returns Thursday, March 10, 0411 4:55:53 PM, but
returns Thursday, March 10, 2011 11:55:53 AM
The difference is 1600 years
This is an example:
$a = ([datetime]::Now).Ticks - ([DateTime]("01/01/0001 00:00")).Ticks
Get-Date $a # get ticks from 01/01/0001 00:00
$a = ([datetime]::Now).Ticks - ([datetime]("01/01/1601 00:00")).Ticks
[datetime]::FromFileTimeUTC($a) # get ticks from 01/01/1601 00:00
It is based on your local "long date" format.
enter image description here
Either you have to change your system "Long Date"
(OR) Use below command
(get-date).tostring("dd/MM/yyyy")
enter image description here
https://technet.microsoft.com/en-us/library/ee692801.aspx
Regards,
Manikandan Boopathy