if i have a function like so:
function setDeadline(uint256 deadline) public returns(uint256){
return deadline;
}
how do I call it from the migration file?
contractName.setDeadline(
//deadline uint256
);
my question is how to input a date in javascript. It will be of the type today+7days.
The uint256 deadline is most likely (not sure without context) a unix timestamp.
You can format the JS Date object as timestamp using the getTime() method. It returns the timestamp in milliseconds, so you'll need to divide it by 1000 to get the timestamp in seconds.
let dateInAWeek = new Date(); // now
dateInAWeek.setDate(dateInAWeek.getDate() + 7); // add 7 days
const deadline = Math.floor(dateInAWeek.getTime() / 1000); // unix timestamp
contractName.setDeadline(deadline);
Related
I have date with this format in my db '1631363150' i want to change it to dd-mm-yyyy (DART)
Let's try if it would be your reference time
void main() {
var date = DateTime.fromMillisecondsSinceEpoch(1631363150 * 1000);
print("get time: ${DateFormat("dd-MM-yyyy").format(date)}");
}
output: get time: 11-09-2021
I will receive DateTime in UTC format from API and I need to convert the DateTime to local time zone based on the condition.
We have toLocal() method to change the time based on the device time zone.
condition: 23-4-2021 // no need to change it to toLocal()
23-4-2021 00:00:00 // no need to change it to toLocal()
23-4-2021 10:30:34 // need to change it to toLocal()
If we have time in the DateTime then only we have to change it in local time.
DateTime utcToDateTimeLocal(DateTime value) {
return value.toLocal();
}
Thanks!
Something like this maybe ?
DateTime utcToDateTimeLocal(DateTime value) {
if (value.hour!=0 || value.minute!=0 || value.second!=0){
return value.toLocal();
}
return value;
}
Here is quick solution that work for me.
You can get time (or any format) by DateFormat class
In your case
dateTime = '23-4-2021 10:30:34'
final format = DateFormat('HH:mm a');
final clockString = format.format(dateTime);
you will get // 10:30 AM
DateTime utcToDateTimeLocal(DateTime value) {
var dateFormat =
DateFormat("dd-mm-yyyy hh:mm a"); // you can change the format here
var utcDate =
dateFormat.format(DateTime.parse(value.toString())); // pass the UTC time here
var localDate = dateFormat.parse(utcDate, true).toLocal().toString();
return DateTime.parse(localDate);
}
I'm fixing a bug in JAVA/Angular Project, I'm getting a Date in Millisecodes from the front End, then I change the date from Millisecondes to "yyyy MM dd HH:mm:ss" format using SimpleDateFormat class in JAVA.
I want to compare the date that I'm getting from the front end with a field in a Table in my DataBase using criteriaBuilder.greaterThan().
The type of the field is bigInit(20).
I proposed as a solution to compare the dates using TimesTamp type, but the request from the client is a comparaison using Date in JAVA
public Specification<T> greater(Object value, String field, String type) {
return (root, criteriaQuery, criteriaBuilder) -> {
Path tuple = getPath(root, field);
System.out.println("type" + tuple.getJavaType());
if (tuple.getJavaType().isAssignableFrom(Date.class)) {
return criteriaBuilder.greaterThan(tuple, convertFilterDateToDate(value.toString()));
}
return criteriaBuilder.greaterThan(getPath(root,field),Double.valueOf(value.toString()));
};
}
This method takes 3 parametrs :
Object value : its type is Long in my case, it is the value of the date taken from the front End, I wrote a method to convert the value from Long to Date using SimpleDateFormat.
String field: its the field in my table, it contains dates with type Long.
String Type: it contains the value 'endDate' in my case.
Below, the definition of getPath Method :
public Path getPath(Root<T> root, String field){
String fiedls[] = field.split("\\.");
if(!field.contains(".")){
System.out.print(root.get(field));
return root.get(field);
}
else if (fiedls.length==2){
Join<Operation,Object> join = root.join(fiedls[0]);
return join.get(fiedls[1]);
}
else if(fiedls.length==3){
Join<Operation,Object> join = root.join(fiedls[0]);
Join<Object,Object> join1 = join.join(fiedls[1]);
return join1.get(fiedls[2]);
}
return null;
}
The request is to compare date using Date type in java and criteriaBuilder.greaterThan() , any Idea ?
For one Client, and only when switch the browser to english, the following code:
convertTimeToDate: function(dateobj) {
if ((dateobj == undefined) || (dateobj == null)) {
return "";
}
var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({
pattern: "dd. MMM YYYY"
});
var dateFormatted = dateFormat.format(dateobj);
return dateFormatted;
},
returns when inputing the highdate '9999-12-31' the datestring '31. Dec 10000' what could be the problem? It is reproducible only on the maschine of this one person, but for her it happens ALWAYS.
To avoid problems with timezones, especially in UI5 apps in HR, I decided to send/receive dates and times in ISO format as strings in my recent developments, it guarantees that a user in browser will see the same value as in the SAP back-end system.
To make sure you use these values both for input and output it is recommended to implement a Custom Data Type.
Suppose you have an sap.m.DateRangeSelection which accepts JavaScript Date objects as dateValue and secondDateValue, and you want bind these properties to a model, where properties like startDate and endDate are date strings of yyyy-MM-dd pattern.
In this case a sample custom data type can be like this:
sap.ui.define([
"sap/ui/model/SimpleType",
"sap/ui/core/format/DateFormat"
], function(SimpleType, DateFormat) {
"use strict";
return SimpleType.extend("MyProject.model.ISODateType", {
/**
* Converts JavaScript Date object to ISO date string
*
* #public
* #param {string} sISO the ISO value of the formatted property
* #returns {string}
*/parseValue: function(oDate) {
var oFormat = DateFormat.getDateInstance({
pattern: "yyyy-MM-dd"
});
return oFormat.format(oDate);
},
/**
* Produces JavaScript Date object from ISO date string
*
* #public
* #param {string} sISO the ISO value of the formatted property
* #returns {string}
*/
formatValue: function(sValue) {
return new Date(sValue);
},
/**
* Validates the value to be parsed (should be ISO date string)
*
* #public
* no client side validation is required
* #returns {boolean} true
*/
validateValue: function(sValue) {
var sPattern = /(\d{4})-(\d{2})-(\d{2})/;
return sValue.match(sPattern);
}
});
});
And the binding in an XML View can look like this:
<DateRangeSelection
width="30%"
dateValue="{
path: '/startDate',
type: 'MyProject.model.ISODateType'
}"
secondDateValue="{
path: '/endDate',
type: 'MyProject.model.ISODateType'
}"
change="onDateIntervalChange"/>
I was plagued by the same 10k date. My pattern was {pattern: 'MMMM Y'}. Changing it to {pattern: 'MMMM yyyy'} solved the problem. I cannot find any documents on the difference between 'Y' and 'y' though.
just an idea: the user did something (whatever) in his browser and timezone is somehow different for him/her. did you try passing a fixed timezone during fomatting? it looks like some seconds are added .. maybe some converting offset or whatever.
https://openui5.hana.ondemand.com/#/api/sap.ui.core.format.DateFormat/methods/sap.ui.core.format.DateFormat.getDateInstance
#since 1.34.0 contains pattern symbols (e.g. "yMMMd" or "Hms") which will be converted into the pattern in the used locale, which matches the wanted symbols best. The symbols must be in canonical order, that is: Era (G), Year (y/Y), Quarter (q/Q), Month (M/L), Week (w/W), Day-Of-Week (E/e/c), Day (d/D), Hour (h/H/k/K/j/J), Minute (m), Second (s), Timezone (z/Z/v/V/O/X/x) See http://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
something like: https://gist.github.com/bvanzyl/b3b64306a7363f0b3e043608b48d8326
formatDateStr: function(data){
if(data === null || data === undefined){
return data;
}else{
var oDate = new Date(data);
var iLocalTime = oDate.getTime();
// Berlin timezone = UTC+1 = 1hr = 60min ahead
// 60min * 60000 for time in milliseconds
var iBerlinOffset = 60 * 60000;
var iLocalOffset = oDate.getTimezoneOffset() * 60000;
var iBerlinTime = iLocalTime + iLocalOffset + iBerlinOffset;
oDate.setTime(iBerlinTime);
var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern : "MMM, dd YYYY" });
var dateFormatted = dateFormat.format(oDate);
return dateFormatted;
}
}
};
The Calendar clicked signal returns a date as follows:
2015-11-13T00:00:00
However, I would like to have a date formatted like this:
Fri Nov 13 2015
This is what I tried:
onSelectedDateChanged:
{
calender.visible = false;
selectedDate = selectedDate.toLocaleTimeString(Qt.LocalDate, Locale.ShortFormat);
textOfSelectedDate.text = Date.fromLocaleTimeString(Qt.LocalDate, selectedDate, Locale.ShortFormat)}
}
textOfSelectedDate is the id of the text box where this date will be displayed.
How can I extract day, month, and year in a desired format from Date returned by Calender?
QML's date type extends Javascript's Date. Thus you can do:
onSelectedDateChanged: {
const day = selectedDate.getDate();
const month = selectedDate.getMonth() + 1; //assuming you want 1..12, getMonth()'s return value is zero-based!
const year = selectedDate.getFullYear();
...
}
First of all, date is similar to JS date type. So you can use all its functions, like getDate() etc. See it here
Also, you can use Qt.formatDate() object to format the result. In your case it can be as follows:
onClicked: {
console.log(Qt.formatDate(date,"ddd MMM d yyyy"))
}