how to increment 1 value in email address for uniqueness in selenium webdriver - email

I am writing test script for signup page and i need to put email address on each time. Can someone help me how to increment by value 1 in the email address as i execute the script for example, test#test.com and next time value should be test1#test.com. I an try with time stamp but not successfully work.
public class GetCurrentTimeStamp
{
public static void main( String[] args )
{
java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));
}
}

If you are trying to provide always unique email id, then you can use date with seconds as it keep changing also you can use
System.currentTimeMillis()
which gives number always unique. so you can append/concatenate it to email, i hope you know it.
You can use below code to get date
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date)); //2016/04/19 16:05:48
depends of simple date format provide 'yyyy/MM/dd HH:mm:ss' output will be displayed.
Thank You,
Murali

Use java.util.Date class instead of Timestamp and format it like so.
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
String email= "test"+ timestamp + "#test.com";

Use below code:-
int num = 1; // Put this stament outside the for loop or put it as global variable.
Now use below code :-
num++;
String email= "test"+ num + "#test.com";
Hope it will help you :)

Related

Date Format For Google Classroom API ScheduledTime

I'm trying to set the scheduled time when creating an assignment using the Google Classroom API. However, I'm confused about which date format is needed. By the error messages, it seems to accept a string which holds a timestamp and a timezone or Z at the end. Among others, I've tried using System.currentTimeMillis() + "Z", as well as googleDate.getValue() + "Z", googleDate.getValue() since Google Date format seems to be the way to go based on this doc but none of them seem to work.
Any ideas perhaps?
Thank you.
String timezone = timestamp + offset + "";
System.currentTimeMillis()
com.google.api.client.util.DateTime googleDate =
new com.google.api.client.util.DateTime(new java.util.Date());
// Date javaDate = new Date(googleDate.getValue());
CourseWork courseWork = new CourseWork()
.setCourseId(course.getId())
.setTitle("title PUBLISHED 2")
.setDescription("desc")
.setScheduledTime(googleDate.getValue() + "Z")
.setMaxPoints(100.0)
.setDueDate(date)
.setDueTime(timeOfDay)
.setWorkType("ASSIGNMENT")
.setState("PUBLISHED")
;
This is what I get when I manually add a timestamp and turn it into a string.
And this using the Google date instead.
And this with the new Java 8 apis
java.time
I recommend that you use java.time, the modern Java date and time API, for your date and time work. The following code gives the same result as the code from your answer.
LocalDate localDate = LocalDate.now().plusDays(7);
String s = localDate.atStartOfDay(ZoneId.systemDefault())
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
System.out.println(s);
Output in my time zone today:
2021-10-20T00:00:00+02:00
Compared to your own answer you have fewer conversions, and you are freed from writing your own format pattern string since the formatter we need is built in.
This worked:
LocalDate localDate = LocalDate.now().plusDays(7);
java.util.Date date1 = java.util.Date.from(localDate.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
String s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(date1);
It seems the imports were using the Google Date class instead of java.util.date.

Flutter how to convert timestamp date time

I am getting date and time from store. In data base its look like this
Need to know how can I show this as DD/MM/YY
I am trying to do like this
String timeString = snapshot.data[index]['lastupdate'].toString();
DateTime date = DateTime.parse(timeString);
print(DateFormat('yyyy-MM-dd').format(date));
Its showing error of Invalid date format
Try like this your lastupdate date is not convertime inDate thats why its showing error
DateTime date = DateTime.parse(snapshot.data[index]['lastupdate'].toDate().toString());
print(DateFormat('dd-MMM-yyy').format(date));
Use function to get date from Timestamp like this:
readDate(Timestamp dateTime) {
DateTime date = DateTime.parse(dateTime.toDate().toString());
// add DateFormat What you want. Look at the below comment example
//String formatedDate = DateFormat('dd-MMM-yyy').format(date);
String formatedDate = DateFormat.yMMMMd().format(date);
return formatedDate;
}
Use the function when you want it.
For example:
Text(readDOB(streamSnapshot.data!["dob"]))
For this you should install intl package. read

How to create a datetime in apex given a datetime string?

With apex, I pass a string like:
2017-02-05T01:44:00.000Z
to an apex function from javascript, however, when attempting to turn it into a datetime, it gives me invalid date/time error. I can create a date with it like
date newdate = date.valueOf(dateString);
but if I do datetime newdate = datetime.valueOf(dateString) I get the error. I don't get why it sees the string as incorrectly formatted to give invalid date/time. When I create just a date instead of datetime, I lose the time and it sets it to 00:00:00.
Thank you to anyone with some insight on how to create the datetime in apex! I have been trying to find the apex format and from what I see. I can't understand why it thinks this is invalid.
Try this.
String inpputString = '2017-02-05T01:44:00.000Z';
DateTime resultDateTime = DateTime.ValueofGmt(inpputString.replace('T', ' '));
System.Debug('resultDateTime>> '+resultDateTime);
Output:
10:10:41:011 USER_DEBUG [4]|DEBUG|resultDateTime>> 2017-02-05 01:44:00

Change times of a reservation (timestamp) using Listbox in GWT

I want to implement a function (with GWT) to change the start- and end-date/time of a reservation!
The start- & end-date of the reservation is saved as a timestamp.
The reservations are saved in a mySQL DB.
The user can choose the day in a datepicker:
final DatePicker chooseDay = new DatePicker();
..
Date startDate = reservation.getStartDate();
..
chooseDay.setValue(startDate);
..
2 ListBoxes:
final ListBox startTime = new ListBox();
final ListBox endTime = new ListBox();
..
startTime.addItem("08:00");
startTime.addItem("08:30");
startTime.addItem("09:00"); (til 18:00)
...
endTime.addItem("08:00");
endTime.addItem("08:30");
endTime.addItem("09:00"); (til 18:00)
I now have the problem, that i don't know how to change between the formats. Reservations are saved as a timestamp, but how can i change just day and hour/minute?
I am a beginner and it would be really nice if you can help me. Thank you :)
Use can use JsDate on the client side:
JsDate jsDate = JsDate.create(startDate.getTime());
int hour = jsDate.getHours();
int mins = jsDate.getMinutes();

How do I convert a Date to an int?

I have this
DateFormat dateFormat = new SimpleDateFormat("MM");
Date date = new Date();
I know the value as 10 but have got no idea how to print it out. How do I convert it to an int? If there even is a way?
date.getMonth()
it is deprecated - you should be using Calendar, but if you don't want to change, that'll do it. It is 0 indexed, so remember to change the resulting value appropriately.
Javadoc