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" />
Related
When the user select a range of dates on the calendar, a modal opens and the input fields of initial and final dates are auto complete with the dates selected previously. The problem is that they are displaying in this format YYYY-MM-DD and I want it to be DD-MM-YYYY. I have tried everything but nothing seems to work.
Here is where I get the dates and fill the inputs:
select: function (info) {
$('#ModalAdd').modal('show');
$('#ModalAdd').appendTo("body");
$('#activoReservar').val($('#selectActivoReserva option:selected').text());
$('#fechaInicial').val(info.startStr);
var endDate = new Date(info.end);
var beforeDay = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate() - 1).toISOString().slice(0,10);
$('#fechaFinal').val(beforeDay);
},
And here are the things I have tried:
$('#fechaInicial').val(info.startStr.format('ddd, DD-MM-YYYY')); //i tried with dd and a single d too. And without any d
$('#fechaFinal').val(beforeDay.format('ddd, DD-MM-YYYY'));
you may create another function (which you can use anywhere else too),
pass a date to that function and return your desired format.
The sample function might look like as follow:
function dateToDMY(date) {
var d = date.getDate();
var m = date.getMonth() + 1; //Month from 0 to 11
var y = date.getFullYear();
return '' + (d <= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y;
}
And you may call the function from select or any other place as follow:
select: function (selectionInfo) {
var startStr = dateToDMY(selectionInfo.start);
}
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
I have 2 date fields issued date and due date.When I choose issued date,due date should be auto populated by adding 10days with selected date. I have written on-change method for this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var issuedDate=new GlideDateTime(g_form.getValue('u_issued_date'))
//var issuedDate=g_form.getValue('u_issued_date')
alert(issuedDate)
var gdt = new GlideDateTime(issuedDate);
gdt.addDays(10)
g_form.setValue('u_due_date',gdt);
}
I am getting an error GlideDateTime is not defined function ().How can I achieve this? Is there any other way?
GlideDateTime is not available on client side. For simple operation like the one you are having you can use javascript Date object. Which is pain to format, but doable, example:
var date = new Date(g_form.getValue('u_issued_date'));
date.setDate(date.getDate() + 10); //add 10 days
g_form.setValue('u_due_date', formatDate(date));
function formatDate (date) {
return date.getFullYear() + '-' +
leadingZero(date.getMonth() + 1) + '-' +
leadingZero(date.getDate()) + ' ' +
date.getHours() + ':' +
date.getMinutes() + ':' +
date.getSeconds();
}
function leadingZero (value) {
return ("0" + value).slice(-2);
}
For more complicated operation you would wish GlideDateTime you will have to use GlideAjax, that will do operations on server side, and provide result.
I am using jquery easyui edatagrid, where one column is of datebox type editor.
I want to auto select today date so that data entry is faster.
Code :
<th field="date" width="50" editor="{type:'datebox',options:{formatter:myformatter,parser:myparser,required:true}}">Date</th>
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return (d<10?('0'+d):d)+'/'+(m<10?('0'+m):m)+'/'+ y;
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('/'));
var d = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var y = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
You can set the date as soon as the grid data is loaded. For example, something like
$('.datebox input').each( function(){ $(this).val(formatDate(new Date())) });
It is a matter of getting the input fields. For me the above works, you can adjust it according to your code. Then you need a function that does the date formatting, for example
function formatDate(value) {
return value.getMonth()+1 + "/" + value.getDate() + "/" + value.getYear();
}
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