How format api wordpress date in flutter - wordpress

I work on flutter api wordpress project . How format date from wordpress api . date came in this format (2019-08-26T16:23:06) . i want to remove second and year . and month like (June , April)

you can use https://pub.dev/packages/intl and DateFormat :
DateTime dateTime = DateTime.parse(data[index]['date']);
String dateformat = DateFormat( "dd.MM.yyyy HH:mm").format(dateTime);

You can create a DateFormat object that fit your needs and use it to format your date.
Head over to the documentation to examples: https://api.flutter.dev/flutter/intl/DateFormat-class.html

I solve my problem with this function
timenow() {
var day = DateTime.parse(
snapshot.data[index].date)
.day;
var month = DateTime.parse(
snapshot.data[index].date)
.month;
var year = DateTime.parse(
snapshot.data[index].date)
.year;
var hour = DateTime.parse(
snapshot.data[index].date)
.hour;
var min = DateTime.parse(
snapshot.data[index].date)
.minute;
return year.toString() +
"/" +
month.toString() +
"/" +
day.toString() +
" " +
hour.toString() +
":" +
min.toString();
} // format date and time

Related

Formatting NgbDate

I have a datepicker using NgbDate. I would like the format to spell out the month, hyphen, year. For example, August-2020. How can I format the following date this way?
effectiveDate = new NgbDate(date.year, date.month, date.day);
effectiveDate = effectiveDate.month.toString() + '-' +
effectiveDate.year.toString();
// the `effectiveDate` is of type `NgbDate`
effectiveDate = new NgbDate(date.year, date.month, date.day);
// you try to assign `string` to `NgbDate` which could work and it's very confusing
effectiveDate = effectiveDate.month.toString() + '-' +
effectiveDate.year.toString();
// instead it's better to create a variable for string value + string interpolation will make it easy to read
const formattedDate = `${effectiveDate.month}-${effectiveDate.year}`;
// or you can convert `NgbDate` into `Date` in the controller
this.jsDate = new Date(effectiveDate.year, effectiveDate.month - 1, effectiveDate.day);
// and use the `date` pipe in the component's HTML
jsDate | date: 'MM-yyyy'

Invalid Date in moment.js datetime addition

I want to add time/duration in HH:mm(eg 00:10) to a Date time in format MM-DD-YYYY HH:MM
I have date and time in 2 separate objects so am trying the below
var plannedStartDate = document.getElementById("date1"); //eg 02-12-2020
var plannedStartTime = document.getElementById("plannedStart1"); //eg 09:00
var plannedStartDateTime = moment(plannedStartDate.value + " " + plannedStartTime.value);
var minutes = $("#duration1").text().split(':')[1];
var hours = $("#duration1").text().split(':')[0];
var date = plannedStartDateTime.add(hours, 'hours').add(minutes, 'minutes').format("MM-DD-YYYY HH:mm");
console.log("Final:"+date); //gives invalid date
What am I doing wrong
Check this working sandbox: https://codesandbox.io/s/compassionate-bas-fg1c2
It adds the hours and minutes to the input date and then prints in a given format
var moment = require("moment");
var input = "2020-02-12";
var hoursMinutes = "9:10";
var hours = hoursMinutes.split(":")[0];
var minutes = hoursMinutes.split(":")[1];
var momentInTime = moment(input)
.add(hours, "hours")
.add(minutes, "minutes");
var converted = moment(momentInTime).format("DD-MM-YYYY HH:mm:ss");
console.log(converted);

format a Microsoft JSON date in JavaScript original format

i am using below function to convert my json date /Date(1450314910930)/
function jsonDateConvert(MyDate_String_Value)
{
var value = new Date
(
parseInt(MyDate_String_Value.replace(/(^.*\()|([+-].*$)/g, ''))
);
var dat = value.getMonth() +
1 +
"/" +
value.getDate() +
"/" +
value.getFullYear();
return dat;
}
My original date in database is 12/16/2015 but above function gives me +1 day ahead like 12/17/2015 please help me to get original date
Try like this,
function jsonDateConvert(MyDate_String_Value)
{
var d=new Date(MyDate_String_Value);
var dat = d.getMonth() +1 +"/" + d.getDate() +"/" +d.getFullYear();
document.getElementById("date_input").value = dat;
}
jsonDateConvert("12/16/2015")
<input type="text" id="date_input" />

How i can current date Outputfilename Data Extract Arcgis Flex

outputFileName = (configXML.outputfilename[0] || "Dataextracted") + ".zip";
outputFileName = outputFileName.replace(/(\\|\/|:|\?|"|<|>|\|)/g, "");
"Dataextracted" change current date time
replace "Dataextracted" with
new Date()
To format it:
var df:spark.formatters.DateTimeFormatter = new DateTimeFormatter();
df.dateTimePattern = "yyyy-MMM-dd-HHmmss";
trace(df.format(new Date())); //output 2016-Oct-13-095823

Getting date as string - need to convert

Programming in Flex 4.5
I'm getting a date as a String.
I don't know what date or hour I'm getting.
I want to convert the string to date and take only the hours & minutes.
For example:
Getting - "2012-02-07T13:35:46+02:00"
I want to see: 13:35.
Suggestions or any other solutions?
After some digging, Solution:
var myDate:Date;
myDate = DateFormmater.parseDateString(myDateString);
var dateResult:String = myDate.getHours() + ":" + myDate.getMinutes();
Thanks anyway! :-)!
You can to use date.getHours() and date.getMinutes(). Try the following:
var d:Date = DateField.stringToDate("your_date_string","YYYY-MM-DD");
trace("hours: ", date.getHours()); // returns 13
trace("minutes: ", date.getMinutes()); // returns 35
private function init():void
{
var isoStr:String = "2012-02-07T13:35:46+02:00";
var d:Date = new Date;
d = isoToDate(isoStr)
trace(d.hours);
}
private function isoToDate(value:String):Date
{
var dateStr:String = value;
dateStr = dateStr.replace(/\-/g, "/");
dateStr = dateStr.replace("T", " ");
dateStr = dateStr.replace("+02:00", " GMT-0000");
return new Date(Date.parse(dateStr));
}
I see you've already got the answer, but for future users, here it is.
var myDateString:String="2012-02-07T13:35:46+02:00"
//This is of the format <yyyy-mm-dd>T<hh:mm:ss><UTC-OFFSET AS hh:mm>
//You could write your own function to parse it, or use Flex's DateFormatter class
var myDate:Date=DateFormatter.parseDateString(myDateString);
//Now, myDate has the date as a Flex Date type.
//You can use the various date functions. In this case,
trace(myDate.getHours()); //Traces the hh value
trace(myDate.getMinutes()); //Traces the mm value

Resources