I cant seem to convert a date in milliseconds (1488520800000) extracted from JSON and put into a variable into a formatted date (2017-03-02). Here's my code:
import java.text.*;
import java.util.*;
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleDateFormat target = new SimpleDateFormat("yyyy-MM-dd");
Date date = source.parse(vars.get("varReviewDatevalue"));
String newDate = target.format(date);
vars.put("varFormattedReviewdateValue",newDate);
Here's the error I get:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.text.*; import java.util.*; log.info("value for variable: 14885208 . . . '' : Typed variable declaration : Method Invocation source.parse
What's weird is that I got similar code to work fine for an extracted date like: March 2, 2017. I can't figure out why the date represented in mills is not converting to a date. Any ideas?
I was using the wrong jmeter element. This post helped me alot: JMeter: Converting extracted time stamp value to date format
I put this code into a JSR223 Sampler and everything worked
import java.text.*;
long timeStamp = Long.parseLong(vars.get("varReviewDatevalue"));
Date date = new Date(timeStamp);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
TimeZone tzInAmerica = TimeZone.getTimeZone("America/Denver");
formatter.setTimeZone(tzInAmerica);
String dateFormatted = formatter.format(date);
vars.put("varFormattedReviewdateValue", dateFormatted);
log.info(dateFormatted);
log.info(vars.get("varFormattedReviewdateValue"));
Related
how to show datetime(timestamp format) form firebase firestore in (dd/mm/yy, hh:mm:ss) in flutter.
please see the images attachedfirebase firestore data
and my code is my code in vscode
You can simply call toDate() function to the dateTime or your firebase timestamp.
You can also convert them into desired format by using DateFormat class
Here is a small function which will return time like 12:37 AM :
import 'package:intl/intl.dart'; //add this import statement for using DateTime class
String getTime(var time) {
final DateFormat formatter = DateFormat('dd/MM/yyyy, hh:mm:ss aa'); //your date format here
var date = time.toDate();
return formatter.format(date);
}
This function will convert your timestamp object to provided format
eg.: July 23, 2021 at 9:22:29 PM UTC+5:30 -> 23/07/2021, 9:22:29 PM
You can refer this document for detailed date formatting.
You can first parse the date to get a DateTime object by using DateTime.parse(string_from_firebase).
Then use the DateFormat class from the intl package.
final DateTime dateToBeFormatted = DateTime.parse(string);
final df = DateFormat('dd/MM/yyyy');
final formatted = df.format(dateToBeFormatted);
I have date from datetimepicker in this format "14-02-2018". Value is string.
I must parse this value to date. I try this way:
new Date(Date.parse('02-03-2018))
But it works only if the format is 2018-03-02
In moment I can't parse too.
var aaa = moment(itemvalue, "DD-MM-YYYY");
Using Moment JS
var date = new Date(moment('02-03-2018', "DD-MM-YYYY"));
console.log(date.toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
I have to find the last date of the last month
I am using a Groovy Script
I can get the date part ok but now I have to turn it into a String in the form yyyyMMdd.
Code so far (and yes it works)
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
Calendar aCalendar = Calendar.getInstance();
// add -1 month to current month
aCalendar.add(Calendar.MONTH, -1);
// set actual maximum date of previous month
aCalendar.set(Calendar.DATE,aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
//read it
lastDateOfPreviousMonth = aCalendar.getTime();
This returns the date in timestamp form
20160229 105925.240
Now I need to extract 20160229 from the timestamp as a string
I've tried just about everything...
If this is running on Java 8, you can use the new Java Time classes:
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAdjusters
String date = LocalDate.now()
.minusMonths(1)
.with(TemporalAdjusters.lastDayOfMonth())
.format(DateTimeFormatter.ofPattern("yyyyMMdd"))
If this is Java 7 or Java 6, you can use Calendar and a bit of Groovy:
String date = Calendar.instance.with {
add(MONTH, -1)
set(DAY_OF_MONTH, getActualMaximum(DAY_OF_MONTH))
time
}.format('yyyyMMdd')
I have been struggling with this even after doing so much of research on such a simple thing, so I need some help here.
I need to pass current date in date data type only in 'yyyy-MM-dd' format. SimpleDateFormat converts current date to string type and while trying to parse though it gets converted to Date type but changes the format.
I need currentDate in the format 'yyyy-MM-dd' of Date Type.
if(!session.dtfromDate && !session.dttoDate)
eq("startDate", currentDate)
I have managed to figure out a solutions to this. First got my desired format which obviously converted it to a String and then parsed this to a Date. It has worked perfectly fine.
SimpleDateFormat nsdf = new SimpleDateFormat('yyyy-MM-dd')
String currentDate = new SimpleDateFormat('yyyy-MM-dd').format(new Date());
Date newDate = (Date)nsdf.parse(currentDate)
if(!session.dtfromDate && !session.dttoDate)
eq("startDate", newDate)
can anyone tell me how to do date validation in GWT please. im passing date as String. it should to be converted to date format and its format is to be validated.
import com.google.gwt.i18n.client.DateTimeFormat;
...
DateTimeFormat myDateTimeFormat = DateTimeFormat.getFormat(...);
Date date = myDateTimeFormat.parseStrict(dateString);
parseStrict() throws an IllegalArgumentException for invalid date strings.
You can use GWT Bean Validation pattern matching expression for String:
#Pattern( regexp = "some javascript regular expression" )
private String dateStr;
or this when you have date:
#DateTimeFormat(pattern = "dd.MM.yy")
private Date myStartDate;
I do not use this but you can see a complete sample in gwt-2.5.0 samples directory.
Have a nice time.