How to convert "PT5H" to ticks using powershell? - azure

I'm trying to convert "PT5H" to ticks format using powershell. But facing below error:
System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'SuppressionDuration'. Cannot convert value "PT5H" to type "System.TimeSpan". Error: "String was not recognized as a valid TimeSpan."
Can anyone help me out in converting "PT5H"(String) to ticks ?

You can use the XmlConvert.ToTimeSpan() method to parse ISO8601 duration strings:
$duration = [System.Xml.XmlConvert]::ToTimeSpan('PT5H')
Command-Name -SuppressionDuration $duration

Related

How to format iso date in nodeJS

Here is my code
var newDateObj2 = moment("2020-04-29T14:05:00.000Z").format('YY/MM/DD,HH:mm:ss.S');
console.log(newDateObj2);
Output
20/04/29,19:35:00.0
Expected Output
20/04/29,14:05:00.0
Why 5.30 (h.mm) getting added in my final result, When i print
moment("2020-04-29T14:05:00.000Z")`=> Moment<2020-04-29T19:35:00+05:30>
How to get Output 20/04/29,14:05:00.0
You should trim the Z from the ISO date string or use the utc() function
moment("2020-04-29T14:06:00.000Z").utc().format('YY/MM/DD,HH:mm:ss.S');

Time data with gmt does not match format input for pandas conversion

How to convert date time string with GMT into a pandas date time format ?
Here is an example :
#date_time is like 12/Dec/2015:18:25:11 +0100
df['date_time'] = pd.to_datetime(df['date_time'], format="%d/%b/%Y:%I:%M:%S %Z")
Here is the error :
ValueError: time data '12/Dec/2015:18:25:11 +0100' does not match
format '%d/%b/%Y:%I:%M:%S %Z' (match)
You'd better check the formatted string:
https://docs.python.org/3/library/datetime.html
Use '%d/%b/%Y:%H:%M:%S %z' instead of '%d/%b/%Y:%I:%M:%S %Z'.

Converting time format

There must be a quick solution for this, but after 30min I gave up and need help.
This is the format of source data
0h56m40s 0h57m10s 1h00m40s 1h02m15s 1h02m25s
52m47s 54m25s 54m52s 57m23s 57m43s
49m30s 54m31s 54m34s 56m35s 56m36s
47m45s 48m03s 51m02s 52m23s 53m05s
46m54s 49m29s 50m51s 51m02s 51m03s
46m09s 47m56s 50m16s 51m20s 51m53s
46m55s 47m08s 47m13s 48m16s 50m11s
and I need this in time format like 0h56m40s to 0:56:40
I tried search/replace, from h to :, m to : and removing s, works for when there's hour, but messes up for when only minutes are there.
Any tips?
You can concatenate 0: if the input string is too short:
=(IF(LEN(A1)<7,"0:","") & SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"h",":"),"m",":"),"s",""))+0
The +0 part converts string to time value (change cell format to h:mm:ss). If you prefer to keep it in text format, remove +0.

convert Oracle DATE to linux time

I'm having trouble converting an Oracle DATE field to a linux time format in perl.
I'm pulling the date field like this:
my $query = "SELECT RESPONSE_DATE FROM TABLENAME";
my $sth = $dbh->prepare($query);
$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
my #results = $sth->fetchrow_array();
printf "response_date=%s",$results[0];
printf "localtime(time)=%s",localtime(time);
Output:
response_date=14-OCT-14 08.35.00.000000 PM
localtime(time)=Tue Aug 18 23:35:13 2015
I can get all the pieces of the local time like this:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
But now I need to compare those pieces with similar pieces of response_date. Any ideas?
I presume you need all the localtime fields for some sort of date calculation?
The Time::Piece module is the usual solution to this. It allows you to parse your database time and also overloads localtime to that it returns a Time::Piece object in scalar context
Unfortunately Time::Piece won't parse the fractional seconds field, so if it's not always zero then you will need to remove it from the date-time string
Clearly other calculations are possible once you have both the database value and the current date as Time::Piece objects
use strict;
use warnings;
use Time::Piece;
use Time::Seconds 'ONE_DAY';
my $s = '14-OCT-14 08.35.00.000000 PM';
my $dt = Time::Piece->strptime($s, '%d-%b-%y %H.%M.%S.000000 %p');
my $now = localtime;
printf "%s was %.3f days ago\n",
$dt->strftime('%a %d-%b-%Y at %H:%M:%S'),
($now - $dt)->days;
output
Tue 14-Oct-2014 at 20:35:00 was 308.190 days ago

vim search for epoch time strings, pipe to date -d and return the date into the file

I have a file with a lot of data in it, one being a last-modified="1231231231"
where 1231231231 is epoch time in milliseconds
<Translation
author_id="25"
id="02f18edd-ef7a-48e2-b614-b5888936017e"
language="de_DE"
last_modified="1325669156960"
phase="1"
target="[ phase="1" language="de_DE" ]"
translation_text="Funktionen"/>
Note the: last_modified="1325669156960"
I can run this:
:%s/\([0-9]\{10\}\)\([0-9]\{3\}\)/\1/g
to find all these occurrences and replace them with a "seconds" string:
last_modified="1325669156"
I can then pattern match on those 10 digits, and what I'd like to do is pipe them to the unix data -d command to return a formatted data stamp:
:%s/[0-9]\{10\}/&/g
In this example, instead of replacing with the same value as I found (I.e, the &),
I'd like to somehow pipe that value to what would be essentially:
date -d &
and return that as a formatted time stamp in the
last_modified="Wed Jan 4 07:13:32 MST 2012"
Any ideas on how to do this? I have to do this about every other week on various files.
You can use strftime() in vim. Find one proper format string to meet your needs.
I'm using %c here:
:%s/last_modified="\zs\(\d\{10}\)\d\{3}/\=strftime('%c', str2nr(submatch(1)))/g
result:
<Translation
author_id="25"
id="02f18edd-ef7a-48e2-b614-b5888936017e"
language="de_DE"
last_modified="2012-1-4 17:25:56"
phase="1"
target="[ phase="1" language="de_DE" ]"
translation_text="Funktionen"/>

Resources