I want to get the current date and time as example date: 11/10/2014 and time 8:30 am or 6:00 pm and pass it as parameters to my Jmeter test. Can some help me do this.
Use __time function:
${__time(dd/MM/yyyy,)}
${__time(hh:mm a,)}
Since JMeter 3.3, there are two new functions that let you compute a time:
__timeShift
"The timeShift function returns a date in the given format with the specified amount of seconds, minutes, hours, days or months added" and
__RandomDate
"The RandomDate function returns a random date that lies between the given start date and end date values."
Since JMeter 4.0:
dateTimeConvert
Convert a date or time from source to target format
If you're looking to learn jmeter correctly, this book will help you.
it seems to be the java SimpleDateFormat : http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
here are some tests i did around 11:30pm on the 20th of May 2015
${__time(dd-mmm-yyyy HHmmss)} 20-032-2015 233224
${__time(d-MMM-yyyy hhmmss)} 20-May-2015 113224
${__time(dd-m-yyyy hhmmss)} 20-32-2015 113224
${__time(D-M-yyyy hhmmss)} 140-5-2015 113224
${__time(DD-MM-yyyy)} 140-05-2015
JMeter is using java SimpleDateFormat
For UTC with timezone use this
${__time(yyyy-MM-dd'T'hh:mm:ssX)}
Use ${__time(yyyy-MM-dd'T'hh:mm:ss)} to convert time into a particular timeformat.
Here are other formats that you can use:
yyyy/MM/dd HH:mm:ss.SSS
yyyy/MM/dd HH:mm:ss
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss
MM/dd/yy HH:mm:ss
You can use Z character to get milliseconds too.
For example:
yyyy/MM/dd HH:mm:ssZ => 2017-01-25T10:29:00-0700
yyyy/MM/dd HH:mm:ss.SSS'Z' => 2017-01-25T10:28:49.549Z
Most of the time yyyy/MM/dd HH:mm:ss.SSS'Z' is required in some APIs. It is better to know how to convert time into this format.
Actually, for UTC I used Z instead of X, e.g.
${__time(yyyy-MM-dd'T'hh:mm:ssZ)}
which gave me:
2017-09-14T09:24:54-0400
Use this format:
${__time(yyyy-MM-dd'T'hh:mm:ss.SS'Z')}
Which will give you:
2018-01-16T08:32:28.75Z
Should have double quotes surrounding the ${}
String todaysDate = "${__time(yyyy-MM-dd'T'HH:mm:ss.SSS'Z')}";
Related
Hello i've been working on how to get yesterday date in DataStage?
CurrentDate()-1
When i compile the job, it gave me an error.
So how should i do to get the yesterday date?
btw that code i'm doing it in the Transformer stage
Assuming you are using the parallel engine in DataStage - this could be a solution
DateOffsetByComponents
DateOffsetByComponents(CurrentDate(), 0, 0, -1)
As the last parameter is the day part and -1 would substract a day
Convert the date into a date type, then you can add or subtract days.
You can use IConv to convert a string into a datastage internal date format. Then you can perform addition/subtraction on the date. Then use OConv to convert the variable back to string format.
If this is done in a transformer stage, you need to do this all in one statement:
OConv(Iconv(VDate ,"D/YMD[4,2,2]") - 1), "D/YMD[4,2,2]")
Hope this helps.
In a parallel Transformer stage, I'd use DateFromDaysSince() function. Use current date function as the base, and -1 as the offset value.
I've been using this answer to convert epoch time to DateTime. I have this epoch number:
epoch = 1549626705942
and do:
Time.at(epoch).to_datetime
However, I get this as the result:
#<DateTime: 51075-09-19T08:45:42+02:00 ((20376082j,24342s,0n),+7200s,2299161j)>
I'm using Ruby version 2.5.3p105 and my clock is set to the current year. This epoch value evaluates to today's date (February 2nd, 2019) yet I get a year 51075. Really not sure what's going on.
It's also weird because, when I enter my timestamp at a site like this one I get today's date but here I get the same result as my Ruby code.
Edit: I tried to remove the last 3 numbers of this date and got a correct date. So is it that there are 2 epoch "formats" so to say?
You are passing miliseconds to the Time::at() method. You should pass seconds there. Link to docs is here.
To retrieve Epoch value(in seconds), use Time#to_i
UPD
This will work for you:
Time.at(0, your_epoch_milliseconds, :millisecond)
I need to get time and date from database date like "2015-08-27T12:09:36Z". I tried but not get any solutions where I get date and time in different variable.
I need to get it in Ruby. No rails in my application.
I used below code but not getting.
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z").in_time_zone
Any one have a experience in it?
Thanks
I don't have enough reputations to comment so am posting comment as answer, are you looking for this
Time.now.strftime('%Y-%m-%dT%H:%M:%SZ')
Which will give the pattern you asked for. Z represent the time zone if you use
%z - Time zone as hour and minute offset from UTC (e.g. +0900)
%:z - hour and minute offset from UTC with a colon (e.g. +09:00)
%::z - hour, minute and second offset from UTC (e.g. +09:00:00)
%Z - Time zone abbreviation name
Check for more
http://apidock.com/ruby/Time/strftime
My Updated answer after your comment
require 'date'
DateTime.parse("2015-08-27T12:09:36Z").strftime('%Y-%m-%dT%H:%M:%SZ')
In your code change Time.strptime('') to DateTime.strptime('')
First, you need to require 'date'. Ruby has built-in Date and Time classes without that require, but the library provides more functionality.
If you have a string retrieved from the database in ISO-8601 format, and you want to turn it into a date and time, just use DateTime.iso8601(string) to get a DateTime object. You can extract the date and time components however you like after that.
irb(main):001:0> require 'date' #=> true
irb(main):002:0> dt = DateTime.iso8601("2015-08-27T12:09:36Z") # DateTime object
irb(main):003:0> d = dt.to_date # Date object
irb(main):004:0> t = dt.to_time # Time object
I am learning programming and I choose Ruby as the first language to learn.
I am parsing an XML where dates are in this form: 1240915075 1224855068
How is this format called? How to use that value in a Date or Time object?
Thank you!
This is UNIX time (sometimes called Epoch time). It measures the number of seconds elapsed since January 1, 1970 (The Unix epoch is the time 00:00:00 UTC on 1 January 1970)
Here's an example converter: http://www.esqsoft.com/javascript_examples/date-to-epoch.htm
A stackoverflow question regarding converting integer time using Ruby: Ruby / Rails: convert int to time OR get time from integer?
use the Time.at function to convert e.g.:
t = Time.at(i)
That's Epoch Time (the first one corresponds to Tue Apr 28 2009 11:37:55 GMT+0100).
You can get a datetime out of it, using Time.at, like this:
Time.at(1240915075)
That is a unix timestamp - the number of seconds since jan 1st 1970.
An example of how to use it in Ruby is here:
t = Time.at(1215163257)
puts t.to_date
>> 2008-07-04
I'm looking at the PayPal IPN docs, and it says the datetime stamps of their strings are formatted as:
HH:MM:SS DD Mmm YY, YYYY PST
So year is specified twice?
Once in double digits, and another with 4 digits?
This looks bizarre.
This seems to be a bug in the documentation. The actual format should be "HH:MM:SS Mmm DD, YYYY PST" (e.g. "08:30:06 Apr 19, 2017 PDT")
Actually in PHP you need to use date("Y-m-d\TH:i:s\Z") . That will result in something that looks like 2012-04-30T00:05:47Z -- I didn't notice a difference between urlencoded and non.
Where are you guys finding this info? This information is elusive in their documentation and cost me an hour or two of hunting and trying stuff. The only place I see this format is in the TIMESTAMP field. Having a hard time with the PayPal NVP API's PROFILESTARTDATE for CreateRecurringPaymentsProfile and a "Subscription start date should be valid" error.
For php, the syntax is date("G:i:s M m, Y T");
this is the correct format according to their documentation - 2010-03-27T12:34:49Z
so it is - YYYY-MM-DDTHH:MM:SSZ (I don't know what the T in the middle and Z is but it's constant for all the dates)
I've created PayPal NVP library in Java, so if you want to check how it works, or use it,
you are more than welcome. it's on sourceforge - payapal-nvp.sourceforge.net
Complete date plus hours, minutes, seconds and a decimal fraction of a
second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
Where TZD = time zone designator (Z or +hh:mm or -hh:mm)
Example
1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.
1994-11-05T13:15:30Z corresponds to the same instant.
https://www.w3.org/TR/NOTE-datetime
PayPal Format to Any format 100% working and easy copy Paste
$payPalFormat = "18:30:30 Feb 28, 2008 PST";
$subrotoFormat = date('Y-m-d', strtotime($payPalFormat));
Result: 2008-02-29
All Format: https://www.w3schools.com/php/func_date_date.asp
https://gist.github.com/subrotoice/d820863ce65eb0d8434a47a76d005df4 (Subroto Biswas Gist)
Actually, I think the right format is: yyyy-MM-ddTHH:MM:ssZ
The case is important.