i made this code for inserting data to an system mail that know to work with xml file.
the problem is that i try to create some javascript code for getting the current date of day, and then put it inside the filed date, but without success.
i know hot create the date in javascript, my problem is in thx xml file, i mean
how can i impplemt the date inside the filed date in the xml file.
the code(xml side):
123456
NOW
COMPLETE
ENGLISH
1274
liran
**
413
3280
86308
;
UNIX
email;dateofday
liroy7#gmail.com;(i want here to return the date from the javascript)
thanks,
I'm not sure I understand, but you can use getTime() on your Date objec to insert it into the XML file as milliseconds, and if you need to convert it back into a JavaScript object you can parse it directly.
function putInXmlFile(d) {
writeToXML(d.getTime());
}
function getFromXmlFile() {
var date = new Date(getFromXML());
}
It works because the JavaScript Date object can parse from the milliseconds from the epoch (which is returned by getTime).
Related
I use Datadatables in server-side mode.
For the date my server return a JSON DATE mode for example:
"2015-12-18T17:04:27Z"
How can I format the DataTables localization automatically format of the language of the browser?
Thank you
Assuming this "2015-12-18T17:04:27Z" is the value returned from the server, here is my take on it.
new Date("2015-12-18T17:04:27Z").toLocaleDateString() // =>"12/18/2015"
new Date("2015-12-18T17:04:27Z").toLocaleString() // => "12/18/2015, 12:04:27 PM"
There are a number of methods you could use to format it how you like here.
Note: The comments are the outputs determined by my Locale, yours may differ
I have a JSON output from a non-configurable system where various date/time variables have values like \/Date(1422691756316)\/
How can I get that into a readable format (I need to display it via PHP and Javascripts).
You could deserialize the JSON output via json_decode() and then you could try to parse the string to an timestamp with strtotime (http://php.net/manual/de/function.strtotime.php), then you could create a date from thins timestamp using the date() method (http://php.net/manual/de/function.date.php) with a given formatting string an the timestamp.
But I'm not sure if your date string is ready to be parsed. In all cases you may to remove the \/Date( and )\/ parts of the string.
EDIT: Looks like your string is not a timestamp, strtotime fails. You may have to check what kind of timestamp/ datestamp/ whatever your string is.
We store every date data in ISO format using new Date().toISOString().
I tried to convert this ISO formatted date into Date object in node.js but I get Invalid Date response.
date string is isoDate = 2014-07-09T14:00:00.000Z
and I did console.log on Date.parse(isoDate); and new Date(isoDate);
but each returns NaN and Invalid Date.
I checked if the date string contains any invisible wrong character but they are fine and can be converted on browser console.
does this mean I need to convert the string manually and create Date object with parsed string?
Thanks for reading.
Try using moment library. It has a lot of functionality to work with dates and can easily be used both on client and server side. Calling moment("2014-07-09T14:00:00.000Z").toDate() would convert your string to a Date JavaScript Object, using this library.
I am posting this answer just in case somebody experience this like I did.
What happened to me is I thought I was sending an ISOString from the browser
{
startDate: date.startDate
}
which in fact I was sending a moment instance as parameter
When I checked in the network inspector I found out that the data being sent is in ISO format - yes, but it is enclosed in double quote ""
{
startDate: "2016-12-31T16:00:00.000Z"
}
it should not be enclosed in double qoutes and should look like this
{
startDate: 2016-12-31T16:00:00.000Z
}
what worked for me is to parse the moment to iso string
{
startDate: date.startDate.toISOString()
}
In the same spirit as discussed here, is there a recommended way to generate / parse dates from within a bash script so that it can be interfaced to Javascript Date?
To be precise, I get this strings when doing json encoding of a Javascript Date object:
2011-10-31T10:23:47.278Z
I could put together a bash hack to generate / parse that date format, but I would prefer to avoid reinventing the wheel. Does somebody have a working solution?
I am more interested in the "generating" side: I want to generate current dates from a bash script and save them in a json document (couchdb) so that they can be automatically ordered by the view engine.
The closest I am coming is this:
date -u +"%FT%T.000Z"
Which gives this output:
2011-11-03T06:43:08.000Z
I do not like that I have to put the T, the Z and the milliseconds to 0 manually (I can use %N for nanoseconds, and truncate with sed or whatever, but seems like overkill just to get millisecond precission), and I was hoping that there would be a built-in format token for date which would produce that UTC date. I assumed - wrongly it seems - that the format is common enough that it can be specified with just one format token.
JavaScript can convert many different values into dates. Not sure if that's what you mean, but for example. Your bash could generate this string: "2011/11/10 08:08:08"
When it gets to JavaScript land you can do this
var date = new Date("2011/11/10 08:08:08")
You can also do this:
var now = 1320287813362
var date = new Date(now)
More info on what Date accepts here:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
Other interesting info here:
What's the best way to store datetimes (timestamps) in CouchDB?
I am working with Javascript and for some requirement I need to connect oracle database and retrieve some data.
How can i read timestamp values from oracle database in java script please provide me the method or any help.
i have checked my database and the format Is "YYYY-MM-DD HH:MM:SS,fffffffff"
How can i read this time stamp value.
Thanks
Lr
you could use oracle's datetime conversion when you select the data TO_CHAR( datetime, format )
like this you can get the datetime as a string from you db in any format you want and don't need to change the format later in Javascript.
see Oracle Format Models
simple example:
SELECT TO_CHAR( SYSDATE, 'MM/DD/YYYY HH24:MM:SS' ) AS TS FROM DUAL
or if you want only the time without date:
SELECT TO_CHAR( SYSDATE, 'HH24:MM:SS' ) AS TS FROM DUAL
If in JavaScript you get a timestamp, then just use
new Date(timestamp)
Cannot be done through JavaScript.
You need a webservice that outputs the required data in a specific format (preferably JSON) and use AJAX (http://api.jquery.com/category/ajax/) to fetch it.