Hi, I am using the below code in my project.
I am posting the notification from one view to another view. passing
string(date) as parameter of Nsnotifiationcenter,but i am not able to
covert passed date into original date format I require.
Related
In thingsboard I have a post-processing function for an server attribute update dialog.
update server attribute widget
post-processing date value
post-processing date value fails
I need to convert a text value (entered by the user in a widget) into a unix time stamp (milliseconds precision) to store it into an thingsboard attribute.
I also want do use this function to display the value in a formatted ISO date string. Something linke YYYY-MM-DD hh:mm:ss.
As I understand, the date.getMonth, getFullYear, ... functions are pretty standard for JavaScript. What do I need to do to use them in thingsboard too?
Is there a better way to convert dates?
You have to call use the new-operator to create a date-object.
See Date - JavaScript | MDN:
The only correct way to instantiate a new Date object is by using the new operator. If you simply call the Date object directly, such as now = Date(), the returned value is a string rather than a Date object.
So instead of
var date = Date(value);
it should be
var date = new Date(value);
However, there is a handy and popular javascript date-library called moment.js. Fortunately it is already bundled with Thingsboard and you can use it in widgets and those post-processing functions.
When using Marshallers, I could use something like:
JSON.registerObjectMarshaller(Date) {
return it?.format("yyyy-MM-dd'T'HH:mm:ss")
}
and it would make all Date objects render to JSON with that format. Is there an equivalent I can use with JSON Views to display Date objects?
The format used for Date is hard coded in JsonOutput.java (https://github.com/grails/grails-views/blob/master/json/src/main/groovy/grails/plugin/json/builder/JsonOutput.java)
I've created an issue about this https://github.com/grails/grails-views/issues/92
A temporary workaround is to duplicate JsonOutput.java and place it in src/main/grails/plugin/json/builder with the format modified to your need.
I want to store dates in database as Normal Gregorian dates. However, I want to enable user view/edit them in Hijri calendar.
Now I have two problems:
Before displaying the date, convert it to Hijri (Done, using DisplayTemplates)
After user edit and submit, convert Hijri value to Gregorian. (My problem)
I now can use FormCollection and invoke a helper method to convert the received Hijri to Gregorian, but I am asking if there is some method to automatically convert the value to Gregorian, maybe something IModelBinder ??
I would like my app to load in the state of a NSDate object when is loaded and be able to save a new state set by a spinner.
My first dea was to get the NSdate object from the spinner then call descriptionWithLocale to get the date as a string, then save this string. But I could not see any methods to load a date as a string into a NSDAte.
Depending on your requirements, you have a couple of options. As Carl and rmaddy pointed out, NSDate conforms to NSCoding, which means it is serializable and can be easily stored in the NSUserDefaults. Here's a nice tutorial on using NSUserDefaults.
Alternatively, you can just store the date as an NSTimeInterval. In that case, you can use any of the following methods to store and retrieve the NSDate object (from NSDate class reference).
+ dateWithTimeIntervalSinceReferenceDate:
+ dateWithTimeIntervalSince1970:
– timeIntervalSinceReferenceDate
– timeIntervalSince1970
The dateWithTimeIntervalSince1970 and corresponding timeIntervalSince1970 methods are useful if you care about storing the date in epoch time.
Instead of converting NSData to NSString, better way is convert to NSTimeInterval (which is double) using NSDate -timeIntervalSince1970 method, then you can sore it in NSUserDefaults if you like.
If you really want save to file you can insert NSDate into NSDictionary object then save NSDictionary with -writeToFile:atomically: method (restore with +dictionaryWithContentsOfFile:)
I'm getting a bunch of information from a web server with SOAP and NSXMLParser, and one of the properties I'm getting is time for when a kid is being picked up...
e.g. a response would be: PT15H
In the documentation it's called: System.TimeSpan pickUpTime
Now, the other properties includes stuff like integers, strings and booleans and I just save them with e.g.
else if([elementName isEqualToString:#"a:LastName"])
{
aParent.lastName = currentElementValue;
}
What do I do with PickUpTime? I need to get the time and show it in a label in a clean manner, like 15:00
You can use NSDateFormatter and give it the proper structure of the strings you are getting. This way it can be converted into an NSDate object for your use, i.e. displaying it as "15:00" and such.
Decided to just use stringByReplacingOccurrencesOfString to remove the letters, since I know that I will always get certain letters... then I can convert it into a NSDate with with the format HH:mm