I'm trying to save a date to MongoDB from FullCalendar in my Grails application.
I'm trying to parse the string 2015-12-27T00:00:00.000Z into the below format:
def startDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.start)
def endDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.end)
But, weirdly when I print the formatted date, I get Sun Dec 28 05:30:00 IST 2014. I don't know what or how that particular date is picked.
You should use lowercase y for year. Uppercase Y is for "Week year".
new Date().parse("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "2015-12-27T00:00:00.000Z")
===> Sat Dec 26 19:00:00 EST 2015
import java.text.SimpleDateFormat;
println new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX").parse("2018-07-30 09:57:15 +0800")
Related
I am trying to add a groovy script in SoapUI to find tomorrow's date using next() in current date.
I am getting the date as expected for all other dates except if the date is 19.
def TodaysDate = new java.util.Date().format("yyyy-MM-dd")
log.info ">>>>>>>>>> TodaysDate="+TodaysDate
log.info TodaysDate.next()
Output:
Wed Jul 19 14:34:29 EDT 2017:INFO:>>>>>>>>>> TodaysDate=2017-07-19
Wed Jul 19 14:34:29 EDT 2017:INFO:2017-07-1:
I tried this also.
def Today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())
log.info Today
NextDay = Today.next()
log.info NextDay
Output:
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-19
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-1:
This next() iterator works fine for other dates. Can you help me understand what I am doing incorrect here?
The format() method returns a String. And when you call next() on a String, it increments the last character. So, character 9 is incremented to the next unicode value, becoming :.
If you want your dates in a specific format, first you call next() in a Date object, then you format it:
def TodaysDate = new java.util.Date()
log.info ">>>>>>>>>> TodaysDate="+TodaysDate.format("yyyy-MM-dd")
log.info TodaysDate.next().format("yyyy-MM-dd")
The will print TodaysDate=2017-07-19 and the next date as 2017-07-20.
Maybe it's worth using TimeCategory in your case? Take a look at this simple code sample:
import groovy.time.TimeCategory
use (TimeCategory) {
println new Date() + 1.day
}
It works fine with any date. Test it with today's date (2017-07-19) - adding 1.day will give you 2017-07-20. Hope it helps.
How can I transform this date format :
Wed Jan 04 2017 18:19:13 GMT+0100 (CET)
To ISO date format?
If I do:
let date = new Date(value);
On Browser and Android works fine but when I use on IOS it returns a invalid date error
Thanks
I have a problem - I use c# Web.api and Angular2. Thats works but Angular convert the date which I do not want / need. The date of the database is correct and angular add 1 hour
{{item.createdate | date:'H:mm' }}
So it shows 20:30 instead of 19:30 which is stored in the database :(
This is part of json repsone:
"createdate": "2016-11-29T19:30:00",
How can I solve this?
Thank you
Ralf
The Reason is there's no timezone information in the datetime string from the database result.
var date = new Date('2016-11-29T19:30:00');
console.log(date); //Tue Nov 29 2016 20:30:00 GMT+0100 (CET)
Written in the Angular2 documentation about the Date Pipe here.
The expression expects a valid datestring format:
YYYY-MM-DDThh:mmTZD (eg 2016-11-29T19:30+01:00)
var date = new Date('2016-11-29T19:30+01:00');
console.log(date); // Tue Nov 29 2016 19:30:00 GMT+0100 (CET)
I would like convert string to date (dd/MM/YYYY) - this is useful for compare dates in TableColumns.
so i use DateTimeStringConverter (the string "01/11/2014" is a value of DatePicker)
DateTimeStringConverter format = new DateTimeStringConverter(Locale.FRANCE,
"dd/MM/YYYY");
Date d1 = format.fromString("01/11/2014");
d1.toString()
I don't obtain the right date but this date = "Mon Dec 30 00:00:00 CET 2013" !!!
I don't understand what is the problem (which in fact should not be a problem) ?
Any ideas ?
Thank you in advance
Fabrice
Convert Long date format to specific short date format.
I want to get the Date from Datepicker(Jcalander) , format to dd-mm-yyyy format and assign to String variable. I tried using codes shown below. But didnt get the date format i want.
SimpleDateFormat simpleFormat = (SimpleDateFormat) jCalendarCombo1.getDateFormat();
Date date = jCalendarCombo1.getDate();
System.out.println(date); // Prints Thu Mar 28 00:00:00 IST 2013
String s = simpleFormat.format(date);
System.out.println(s); // prints Thursday, March 28, 2013
System.out.println("Date SHORT format: " + DateFormat.getDateInstance(DateFormat.SHORT).format(date)); // prints 3/28/13
If you want a fixed, non locale dependent format, you can just create it yourself;
SimpleDateFormat shortformat = new SimpleDateFormat("dd-MM-yyyy");
String s = shortformat.format(date);
System.out.println(s); // Prints 29-03-2013