I am making a request for data and parsing it in JSON format however I do get errors because it returns timestamps in the javascript form new Date(1500000). How do I go about fixing this issue.
I thought of using regex to put quotes around the new Date(0000000) but it doesn't seem to work. I am using RegexKitLite and SBJSON. Thanks in advance for the help
You can simply use;
value = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
where value is your "Date(1500000)" string.
Related
I have a time string, which looks like this: 20170822T194135+00. This is called basic ISO:8601 format, if I understood correctly.
When I try to parse it using ZonedDateTime, it throws exception, complaining that it can't parse it.
SO, how do I convert this string to a valid Joda datetime object?
Do I need to build manual "format" to parse it (this would be silly, considering it's a standard format)?
Desperately, I've actually tried to implement custom format:
const time = ZonedDateTime.parse(timeString, DateTimeFormatter.ofPattern(`yyyyMMdd'T'HHmmssZ`));
But, it throws error on column 15. Looks like it fails to parse the timezone. Is my implementation correct? How do I make it work?
I could do it using the pattern x as described in the docs (this pattern accepts offsets like +00).
Then I parsed directly to a ZonedDateTime:
const formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssx");
const time = ZonedDateTime.parse("20170822T194135+00", formatter);
The resulting time variable has the value equivalent to 2017-08-22T19:41:35Z.
The built-in formatters (such as ISO_LOCAL_DATE_TIME) can't parse this format, so the only way seems to be creating a formatter.
I have Date data and converted to string "2014-04-16 08:27:52" from my local PostgreSQL.
Please explain me how to set it at Parse.com as Date datatype?
In the docs on rest API search on date and see the json type and format :
"__type":"Date","iso":"2011-08-21T18:02:52
That would be Included in the date elements json used in the post.
I just figured it out:
var date = new Date("2014-04-16 08:27:52");
object.set("last_update",date);
In PHP, you can do:
$parse->someDate = $parse->dataType( 'date', '1985-01-01' );
In JavaScript, you can do:
var someDate = new Date("1985-01-01");
yourclass.set( 'someDate', { "__type": "Date", "iso": someDate.toISOString() } );
For Parse.com and PHP, the answer is less straight forward than what is presented here. It took me a while to figure out that dataType() isn't working for some reason in the SDK.
It seems many people got the $parse->dataType() syntax from here. But I can't find this function anymore in the official SDK.
Then there is this bug and the resulting function from StackOverflow, but neither of these are very user friendly.
As it turns out, the Parse PHP SDK will handle an array for the value in the createdAt, updatedAt, and other special data types.
This code works (essentially a direct port from their REST API / JavaScript):
$query->greaterThanOrEqualTo("createdAt", ["__type" => "Date", "iso" => date('Y-m-01\TH:i:s')]);
Feel free to use that format for other special types, like GeoPoints.
I have a scaffold form with a field 'date:date' and I want to convert it to a string after the form has been submitted to use it in creating another model, what is the best way of doing this? This has some info but none of the methods work, maybe the scaffold date object is different from a regular Date object?. I know I can rescaffold it as a string but I need to convert it.
review_params[:date].to_s(:db) returns a NoMethodError
This worked for me, if anyone else has same issue with extracting date from 1 form and using it to create another model.
date_string = "#{review_params['date(1i)']}-#{review_params['date(2i)']}-#{review_params['date(3i)']}"
#concert = Concert.find_or_create_by!(artist: review_params[:artist], venue: review_params[:venue], date: date_string)
I am in the unfortunate position that I need to use a composite id in a Grails app where I work with legacy data. This means I have to override some actions in the controller, but as I did this I was struck by the fact that I could not use use a date argument directly as a parameter to a dynamic method.
Instead of just doing MyLegacyObj.findBySystemIdAndLogDate(params.systemId, params.logDate), I first needed to parse the date string before giving it to the dynamic method. To further complicate matters I had no idea what format the date string had (until I added lots of log.debug() string to the output). So now I have a bit of code looking like this
def formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy")
MyLegacyObj.findBySystemIdAndLogDate(params.systemId, formatter.parse(params.logDate));
This feels unoptimal, no to say dangerous (what if the date format changes with the locale?)? What would be a recommended way of doing this, and do I really need to parse dates at all?
Date is a pretty complex object and params are just Strings, so Date is submitted in parts. It is "magically" assembled from the parts when assigning x.properties = params.
Command object will do the work for you, if you add a Date field to it.
It has nothing to do with methods' dynamic or static invocation. Your GSP that renders Date editor might interfere too.
Am getting date (10/02/2011) in xmlresponse how to get this value in to string using NSXmlParserDelegate. "/" blocks me and am not getting how to handle this..
Thanks in advance..
Use NSDateFormatter to get date from NSString from any formats.
You have not been clear where this xml data is coming from, I couldnt turn anything up on how dates should be formatted in xml. The first thought is "you are doing it wrong" if you can try using a different separator for dates, parse them out of the stream before you give the data to NSXMLParser. I know which I would prefer.