"ion-datetime" default time not equal now time in ionic2 - date

I have small issue with "ion-datetime"
I want to change the default time of "ion-datetime" to make it such as today date, time.
So how can I change the default value of "ion-datetime" in ionic 2 because when I click on input field, the application show me the time reduced by 3 hours

Try Below code:
In your.ts File:
let current_datetime: any;
ionViewDidEnter(){
let Today = new Date().toISOString();
let date = String(Today).substr(0,10)
let Time = new Date().toLocaleTimeString();
this.current_datetime = date+" "+Time;
}
In Your .html File:
<ion-datetime displayFormat="YYYY/MM/DD HH:mm:ss" [(ngModel)]="current_datetime"></ion-datetime>

Javascript time library are not well matched for IONIC ISO 8601 Datetime Format
I recommend using moment.js.
Go to you folder application, run : npm install moment --save
In your page.ts add: import * as moment from 'moment';
Declare your variable: myDate= moment().format();
Now just use ion-datetime like this:
<ion-datetime displayFormat="MMM DD, YYYY HH:mm" [(ngModel)]="myDate"></ion-datetime>
I hope this helps.

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

Notifications job date format

I need a hint: how to change date format on jobs notification?
I can't figure it out. As far as I understand, is related to messages.properties file, which I
can't find.
I created i18n directory with messages.properties file, but I'm not sure what is the format of messages file content. (found on albundy83 comment)
Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
String dateStartedIso8601 = dateS.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
Date dateE = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateEnded.toString() )
String dateEndedIso8601 = dateE.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
I have installed Rundeck 3.2.2 using RPM on CentOS 8.
Regards,
Adi
To use that custom format you need to create a groovy plugin, follow this. Basically you need to create a .groovy file and put it on $RDECK_BASE/libext (as any plugin).
I did an basic example modifying this plugin and this. Take a look:
import java.text.SimpleDateFormat
import java.util.Date
import com.dtolabs.rundeck.plugins.notification.NotificationPlugin;
rundeckPlugin(NotificationPlugin){
onstart {
println("job start: data ${execution}")
true
}
onfailure {
println("failure: data ${execution}")
true
}
onsuccess {
Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
String customdate = dateS.format( "dd-MM-YYYY" )
println("success: data ${customdate}")
true
}
}
Output (success job execution):
success: data 18-02-2020

Typescript thinks getYear does not exist on type Date

I'm running tsc inside a webpack project, with "core-js": "registry:dt/core-js#0.0.0+20160725163759" and "node": "registry:dt/node#6.0.0+20160909174046"
Other date properties work fine:
private dateToString (date: Date) {
let month = date.getMonth();
let day = date.getDate();
let year = date.getYear() + 1900;
let dateString = `${month}/${day}/${year}`;
return dateString;
}
Typescript recognizes date.getMonth and date.getDate just fine, but on date.getYear it gives
Property 'getYear' does not exist on type 'Date'.
What definition am I missing?
That API is deprecated. Try getFullYear() instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
The getYear() method returns the year in the specified date according to local time. Because getYear() does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
Change this line from
let year = date.getYear() + 1900;
to
let year = date.getFullYear();

Save date as timestamp in CQ5

I need t use the CQ5 xtype 'datefield' since I need only the date and not time tombe entered by the author.
But the issue is that 'datefield' saves the date in JCR as a String and not as a timestap [ as it does when 'datetime' is used.]
Is there a work around to save the date as a timestamp ?
I don't think it is possible to save the date as timestamp using datefield, without meddling with the default script. But as a workaround, you can use datetime and set the property hideTime to true, to hide the time part, so that the author will not be able to author it.
The json for the config is shown below.
{ "fieldLabel":"Date",
"xtype":"datetime",
"hideTime":true,
"name":"./date",
"defaultValue":"now",
"jcr:primaryType":"cq:Widget"
}
You can add defaultValue to 'now', if you want current date to be initialized as the default, if not explicitly filled in by the author, else it can be ignored.
NOTE: The defaultValue: 'now' doesnt work for me in IE (i am using IE 11 and emulating the previous versions through dev tools), but it works fine in Chrome and Mozilla.
A rough workaround for your jsp:
<%#page import="java.text.SimpleDateFormat,java.util.Date"%>
<%
SimpleDateFormat displayDateFormat = new SimpleDateFormat("dd MMM yyyy");
String dateField = properties.get("nameofdatefield", "");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
Date formattedDate = sdf.parse(dateField);
String formattedDateStr = displayDateFormat.format(formattedDate);
out.println('Example of formated string'+formattedDateStr);
%>
From the above, you can also convert it to a Date Object, depending on what you wish to manipulate.
Let me know if the above example helps

How to modify the date?

I cannot get the add function in Blackberry Java.
// Date
private static DateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
private static Calendar cal = Calendar.getInstance();
public static final String date = dateFormat.format(cal.getTime())
.toString();
The cal variable don't have add function because I want to reduce 1 day from current date.
The source stated that used cal.add(Calendar.DATE, -1);.
The following solution works when using Java SE. I haven't verified using BlackBerry Java ME yet. But, given that I am only using functions that exist in both the SE version of Calendar and the BlackBerry version of Calendar, hence I have a good feeling about the accuracy of this solution. Append these lines to your code:
long curTime = cal.getTimeInMillis();
curTime -= 1000*60*60*24;
cal.setTimeInMillis(curTime);
System.out.println(dateFormat.format(cal.getTime()).toString());
Try this:
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(cal.getTime() - DateTimeUtilities.ONEDAY);
Updated, based on ecb0628's answer and paulkayuk's comment.
Check Calendar, getTimeInMilis(), setTimeInMillis(long millis), and DateTimeUtilities.ONEDAY.