I need a hint: how to change date format on jobs notification?
I can't figure it out. As far as I understand, is related to messages.properties file, which I
can't find.
I created i18n directory with messages.properties file, but I'm not sure what is the format of messages file content. (found on albundy83 comment)
Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
String dateStartedIso8601 = dateS.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
Date dateE = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateEnded.toString() )
String dateEndedIso8601 = dateE.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
I have installed Rundeck 3.2.2 using RPM on CentOS 8.
Regards,
Adi
To use that custom format you need to create a groovy plugin, follow this. Basically you need to create a .groovy file and put it on $RDECK_BASE/libext (as any plugin).
I did an basic example modifying this plugin and this. Take a look:
import java.text.SimpleDateFormat
import java.util.Date
import com.dtolabs.rundeck.plugins.notification.NotificationPlugin;
rundeckPlugin(NotificationPlugin){
onstart {
println("job start: data ${execution}")
true
}
onfailure {
println("failure: data ${execution}")
true
}
onsuccess {
Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
String customdate = dateS.format( "dd-MM-YYYY" )
println("success: data ${customdate}")
true
}
}
Output (success job execution):
success: data 18-02-2020
Related
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.
I have small issue with "ion-datetime"
I want to change the default time of "ion-datetime" to make it such as today date, time.
So how can I change the default value of "ion-datetime" in ionic 2 because when I click on input field, the application show me the time reduced by 3 hours
Try Below code:
In your.ts File:
let current_datetime: any;
ionViewDidEnter(){
let Today = new Date().toISOString();
let date = String(Today).substr(0,10)
let Time = new Date().toLocaleTimeString();
this.current_datetime = date+" "+Time;
}
In Your .html File:
<ion-datetime displayFormat="YYYY/MM/DD HH:mm:ss" [(ngModel)]="current_datetime"></ion-datetime>
Javascript time library are not well matched for IONIC ISO 8601 Datetime Format
I recommend using moment.js.
Go to you folder application, run : npm install moment --save
In your page.ts add: import * as moment from 'moment';
Declare your variable: myDate= moment().format();
Now just use ion-datetime like this:
<ion-datetime displayFormat="MMM DD, YYYY HH:mm" [(ngModel)]="myDate"></ion-datetime>
I hope this helps.
def cleantz( time : String ) : String = {
var sign_builder= new StringBuilder ++= time
println(sign_builder)
var clean_sign = ""
if (sign_builder.charAt(23).toString == "-"){
clean_sign= sign_builder.replace(23,24,"-").toString()
}else{
clean_sign = sign_builder.replace(23,24,"+").toString()
}
var time_builder= new StringBuilder ++= clean_sign
if (time_builder.charAt(26).toString == ":"){
val cleanz = time_builder.deleteCharAt(26)
cleanz.toString()
}else{
time_builder.toString()
}
}
val start = ISO8601Format.parse(cleantz(01/01/2017 6:54 PM))
I get this error:
java.lang.StringIndexOutOfBoundsException: String index out of range: 23
java.time
For the sake of completeness I should like to contribute the modern answer. It’s quite simple and straightforward.
I am sorry that I can neither write Scala code nor test it on my computer. I have to trust you to translate from Java.
private static DateTimeFormatter inputFormatter
= DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a", Locale.US);
public static String cleantz(String time) {
return LocalDateTime.parse(time, inputFormatter)
.atOffset(ZoneOffset.ofHours(1))
.toString();
}
Now cleantz("01/01/2017 6:54 PM") returns 2017-01-01T18:54+01:00, which is in ISO 8601 format. I would immediately suppose that you’re set. If for some reason you want or need the seconds too, replace .toString(); with:
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
Now the result is 2017-01-01T18:54:00+01:00. In both cases the milliseconds would have been printed if there were any.
Since AM and PM are hardly used in other languages than English, I suggest you give an English-speaking locale to DateTimeFormatter.ofPattern() (in my example I used Locale.US). Failing to provide a locale will cause the code to fail on many computers with non-English language settings.
Why java.time?
SimpleDateFormat and friends are long outdated and notoriously troublesome. I cannot count the questions asked on Stack Overflow because SimpleDateFormat behaved differently from what every sane programmer would have expected, or offered no help to debug the simple errors we all make from time to time.
Joda-Time was good for a long time. Today the Joda-Time homepage says:
Note that Joda-Time is considered to be a largely “finished” project.
No major enhancements are planned. If using Java SE 8, please migrate
to java.time (JSR-310).
java.time is the modern Java date & time API built using the experience from Joda-Time and under the same lead developer, Stephen Colebourne. It is built into Java 8 and later, and a backport exists for Java 6 and 7, so you can use the same classes there too.
Assuming that your input string is 01/01/2017 6:54 PM: it has 18 characters. When you call charAt(23), it tries to get the character at position 23, which doesn't exist: the string has positions from zero (the first 0) to 17 (the M). If you try to get a position greater than that, it throws a StringIndexOutOfBoundsException.
But you don't need to do all this string manipulation. If you have a string that represents a date in some format, and want to convert it to another format, all you need is:
parse the original string to a date
format this date to another format
So you need 2 different Joda formatter's (one for each step). But there's one additional detail.
The input has a date (01/01/2017) and a time (6:54 PM), and the output has a date (2017-01-01), a time (18:54:00.000) and the UTC offset (+0100). So you'll have an additional step:
parse the original string to a date
add the +0100 offset to the parsed date
format this date to another format
With Joda-Time, this can be achieved with the following code:
import org.joda.time.DateTimeZone
import org.joda.time.LocalDateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.ISODateTimeFormat
val fmt = DateTimeFormat.forPattern("dd/MM/yyyy h:mm a")
// parse the date
val localDate = LocalDateTime.parse("01/01/2017 6:54 PM", fmt)
// add the +01:00 offset
val dt = localDate.toDateTime(DateTimeZone.forOffsetHours(1))
// format to ISO8601
print(ISODateTimeFormat.dateTime().print(dt))
The output will be:
2017-01-01T18:54:00.000+01:00
Note that the offset is printed as +01:00. If you want exactly +0100 (without the :), you'll need to create another formatter:
val formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
println(formatter.print(dt))
The output will be:
2017-01-01T18:54:00.000+0100
This is the code I used to achieve the same result. The error occurred because I was trying to parse the wrong date format.
val inputForm = new SimpleDateFormat("MM/dd/yyyy h:mm a")
val outputForm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
val dateFormat1 = start_iso
val dateFormat2 = stop_iso
val start = outputForm.format(inputForm.parse(start_iso))
val stop = outputForm.format(inputForm.parse(stop_iso))
println(start)
println(stop)
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"));
I've developing a Rest API and using Jackson library for Json processing.
In my POJO I've defined few java.util.Date fields and I'm parsing these dates using ObjectMapper.
Problem is that all the dates are coming as wrong.
Here is example Json data received from client:
{
"Date1":"20161208 121500",
"Date2":"20161205 131515",
"Date3":"19830201 122718"
}
Here is code snippet:
private final SimpleDateFormat df = new SimpleDateFormat("yyyyMMDD hhmmss");
ObjectMapper mapper = new ObjectMapper();
mapper.setTimeZone(TimeZone.getDefault());
mapper.setDateFormat(df);
MetaData mData = null;
try {
mData = mapper.readValue(metaData, MetaData.class);
}
catch(JsonProcessingException jpe) {
return Response.status(Status.BAD_REQUEST).build();
}
When Date object is created, its off by few months. When I print the dates in log, I get the following:
Date1: 01/08/16 00:15:00 (Original date is 12/08/2016)
Date2: 01/05/16 13:15:15 (Original date is 12/05/2016)
Date3: 01/01/83 00:27:18 (Original date is 02/01/1981)
Can anyone see what I'm doing wrong :(
Thanks a lot!
You have the incorrect datetime pattern. The pattern should be yyyyMMdd hhmmss.
'D' for Day in year and 'd' for Day in month.