JavaFX8 Convert String to date using DateTimeStringConverter - date

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

Related

how to find difference btw 21:00 pm - 1:00 am in flutter

can someone please humbly help me? im fining it extremely confusing.
the dates are like this
1st date ~ 2 May 21:00
2nd date ~ 3 May 04:00
Let's say we have two dates.
var d1 = '2 May 04:00';
var d2 = '3 May 05:00';
First, add this intl package to your project and import it
import 'package:intl/intl.dart';
Next, you need to set a dateformat for your dates above:
var dFormat = DateFormat('d MMM HH:mm');
The date format should be same as your dates orelse you will get an error.
Next, convert the datetime string to your desired format.
var dateTime1 = dFormat.parse(d1, true);
var dateTime2 = dFormat.parse(d2, true);
You can set true if you want UTC time.
Lastly, to get difference between two dates just do the following:
print(dateTime2.difference(dateTime1).inHours); //25
The above print statement will return 25 as the difference between both the given time is 25hours. You can get difference in Minutes too.
Happy Coding!

Angular2 - convert unfortunately date

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)

Issue saving a string as ISO date format

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")

Groovy Date code producing unexpected output

Why is below code producing output like this ?
String oldDate = "2013-12-05 01:34:54.270"
Date date = Date.parse( 'yyyy-mm-dd hh:mm:ss', oldDate )
Output : Sat Jan 05 01:34:54 EST 2013
When it should simply produce December 5 as the date in the output ? In fact in the original string whatever month I put in it produces the exact same output.
The problem is your date format isn't correct. mm is for minutes where MM is for month. So it should be:
String oldDate = "2013-12-05 01:34:54.270"
Date date = Date.parse( 'yyyy-MM-dd hh:mm:ss', oldDate )
You can find out more from the Java API docs for SimpleDateFormat.

Convert Long date to specific short date format

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