SAPUI5 - Dateformat - How format a date with Dateformat - date

let's say I have a Date as a String, formated in yyyy-MM-dd, and I want it to be formated as style:"short".
I want just to use Dateformat.
I used this https://openui5.hana.ondemand.com/#docs/guide/91f2eba36f4d1014b6dd926db0e91070.html to get an idea of how to use DateFormat.
But I can't see, what's wrong with my code:
date: function(sdate) {
var regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
if (!sdate.match(regex))
return "no valid date given";
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oDateFormat = sap.ui.core.format.DateFormat.getInstance({pattern: "yyyy-MM-dd", style: "short"});
return oDateFormat.format(sdate); //date should be returned here in "short"-style
}
The console tell's me
TypeError: j.getTime is not a function.
Also it seems like the WebIDE doesn't know a function Datetime.format().
Can you help?

You'd probably reread the documentation in your link: to convert String into JS Date, you have to use DateFormat.parse method.

Related

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 get a date in the format "2020-01-10T08: 47: 36.264Z"?

I am trying to get a date in the format "2020-01-10T08: 47: 36.264Z", but I have not succeeded, I try to use the toIso8601String (), toUtc (), toLocal () method, but I do not return the format required.
I am new to flutter.
Thanks.
To format a date in Flutter, you can follow this step:
Import the intl package.
Create a method to format your date like this.
String formatDate(DateTime date) { DateFormat formatter = DateFormat ('yyyy-MM-dd');
return formatter.format(date); }
So you will go to where you want to format your date and call the formatDate method and pass your date.
Would this help?
DateTime now = DateTime.now();
String formattedDate = DateFormat('dd-MM-yyyy HH:mm:ss').format(now);

Extract the date format from react-intl

I have a component that uses a datepicker. The datepicker needs a dateFormat property that fits the momentjs pattern, for example 'DD.MM.YYYY' or 'MM/DD/YYYY'.
The date formatting is handled by react-intl. This works fine when converting from a date to a string (via formatDate). However, I need to retrieve the pattern as described above.
My goal is to do something like
dateFormat = this.props.intl.extractDateFormat() // returns 'DD.MM.YYYY'
I have found this similar question, but the only answer relies on parsing the string, which I cannot do, because I do not know whether Day or Month will come first in the formatted date.
If it is possible to convert this string to a date and somehow retrieve the format from momentjs, that would also be a good solution.
I was able to get the date format from react-intl. To do this, I defined an example date and had it formatted by react-intl, and then parsed the format by referring to the original string.
My component which is exported as injectIntl(Component) has this method:
deriveDateFormat = () => {
const isoString = '2018-09-25' // example date!
const intlString = this.formatDate(isoString) // generate a formatted date
const dateParts = isoString.split('-') // prepare to replace with pattern parts
return intlString
.replace(dateParts[2], 'DD')
.replace(dateParts[1], 'MM')
.replace(dateParts[0], 'YYYY')
}
The date will e.g. be formatted to '09/25/2018', and this function would return 'MM/DD/YYYY', a format which can be used by Moment.js.
This function only works if you know that the month and day will always be displayed with two digits. It would fail if the format is something like 9/25/2018.
I have not found a way to extract the date format from react-intl directly.

Typescript parse string dd-mm-yyyy to date

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>

Passing date in Date data type only in groovy

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)