I have this in my pre-request script:
var moment = require("moment");
postman.setEnvironmentVariable("current_timestamp", moment().add(10, 'seconds').valueOf());
This returns 13 digit value for timestamp,But my server only accepts upto 10 digits (until seconds) and after this i want to pass the 10 digit value in my request body :
"carid": "c1234",
"timestamp":{{current_timestamp}},
"lastCoordinates": {
"uuid": "2df38805-b0f8-4f8f-947e-c53e98d63ff6",
Any help is greatly appreciated!!
moment().add(10, 'seconds').unix()
use epoch time stamp using unix()
What you are getting in value of is the unix millisecond time stamp which is 13 digit , if you want 10 digit get epoch time
https://momentjs.com/docs/#/parsing/string-format/
Note that this will have time in second format and doesn't consist of millisecond part;
output :
Related
I have a server where it return time in __time32_t formate I want to get time in milisecond formate from __time32_t. Is it possible?
localtime_s(&ptm, &close_time);
std::wcsftime(buffer, 32, U("%Y.%m.%d %H:%M:%S"), &ptm);
result[U("close_time")] = web::json::value::string(buffer);
__time32_t only contains seconds, not milliseconds. https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/time-time32-time64?view=msvc-170
So no, it's not possible
I am new in Laravel and using 5.5 ver. I have two input field star_time and end_time
Start time Input Value is : 10:00AM
End Time Input value is: 01:00PM
this is my validation rule
$validator = Validator::make($request->all(),[
'start_time' => 'required|date_format:H:iA',
'end_time'=>'required|date_format:H:iA|after:start_time',
]);
every time given "The end time does not match the format H:iA"
Please help how to validate start time and end time and end time bigger than start time and time format with am/pm
This is late answer to you question but here is solution for it. just write H as h in you validator.
$validator = Validator::make($request->all(),[
'start_time' => 'required|date_format:h:iA',
'end_time'=>'required|date_format:h:iA|after:start_time',
]);
You should use h instead of H as you are using A for AM and PM.
H work for 24 hours
h work for 12 hours
A (use upercase) work for AM or PM
Using the default delta time field for Django, but as most know it returns horrifically. So I have developed my own function, convert_timedelta(duration). It computes days, hours, minutes and seconds, just like you might find on this website. It works like a charm on a single time ( I.e. when I was calculating an average time for one specific column ) .. However now I'm modifying how this works so it returns multiple times for a column... Separating times returned grouped by their ID, rather than just having one set time returned. So now I have multiple times returned, which works fine with the default formatting. But when I apply it to my function it doesn't like it and no particular informative errors are alerted.
def convert_timedelta(duration):
days, seconds = duration.days, duration.seconds
hours = days * 24 + seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 60)
I am struggling with something that should be relatively straight forward, but I am getting nowhere.
I have a bunch of data that has a timestamp in the format of hh:mm:ss. The data ranges from 00:00:00 all 24 hours of the day through 23:59:59.
I do not know how to go about pulling out the hh part of the data, so that I can just look at data between specific hours of the day.
I read the data in from a CSV file using:
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
time = row['Time']
This gives me time in the hh:mm:ss format, but now I do not know how to do what I want, which is look at the data from 6am until 6pm. 06:00:00 to 18:00:00.
With the times in 24 hour format, this is actually very simple:
'06:00:00' <= row['Time'] <= '18:00:00'
Assuming that you only have valid timestamps, this is true for all times between 6 AM and 6 PM inclusive.
If you want to get a list of all rows that meet this, you can put this into a list comprehension:
relevant_rows = [row for row in reader if '06:00:00' <= row['Time'] <= '18:00:00']
Update:
For handling times with no leading zero (0:00:00, 3:00:00, 15:00:00, etc), use split to get just the part before the first colon:
> row_time = '0:00:00'
> row_time.split(':')
['0', '00', '00']
> int(row_time.split(':')[0])
0
You can then check if the value is at least 6 and less than 18. If you want to include entries that are at 6 PM, then you have to check the minutes and seconds to make sure it is not after 6 PM.
However, you don't even really need to try anything like regex or even a simple split. You have two cases to deal with - either the hour is one digit, or it is two digits. If it is one digit, it needs to be at least six. If it is two digits, it needs to be less than 18. In code:
if row_time[1] == ':': # 1-digit hour
if row_time > '6': # 6 AM or later
# This is an entry you want
else:
if row_time < '18:00:00': # Use <= if you want 6 PM to be included
# This is an entry you want
or, compacted to a single line:
if (row_time[1] == ':' and row_time > '6') or row_time < '18:00:00':
# Parenthesis are not actually needed, but help make it clearer
as a list comprehension:
relevant_rows = [row for row in reader if (row['Time'][1] == ':' and row['Time'] > '6') or row['Time'] < '18:00:00']
You can use Python's slicing syntax to pull characters from the string.
For example:
time = '06:05:22'
timestamp_hour = time[0:2] #catch all chars from index 0 to index 2
print timestamp_hour
>>> '06'
should produce the first two digits: '06'. Then you can call the int() method to cast them as ints:
hour = int(timestamp_hour)
print hour
>>> 6
Now you have an interger variable that can be checked to see if is between, say, 6 and 18.
I have scratched my brains enough to find my last resort here . I am calling an API which takes values like below for the lastUpdatedTime paramter :
lastUpdatedTime : 1499591547769
lastUpdatedTime : 1499591547770
So i assume the above values are converted to miliseconds since there are 13 digits (1499591547770 & 1499591547769).
Below is what i want to do in simple english .
Get the UTC time now and subtract 15 minutes from it .
Send that value to the API and fetch the data.
My problem is time conversion .
Below is what i am doing in python.
update_time = (datetime.utcnow() - timedelta(minutes=15)).strftime('%m/%d/%Y %H:%M:%S')
update_time_check = (calendar.timegm(time.strptime(update_time, '%m/%d/%Y %H:%M:%S')))*1000
The value for the above is something like 1502247759000
When i send that value (lastUpdatedTime = 1502247759000) to the API , i get a blank result set .
Please let me know if my steps are correct in generating the timestamp which the API is expecting .
Thanks in advance.