In html file I need to display when that file was saved (time and date)
How can i do it? JavaScript?
<script>
var d = new Date(0);
document.getElementById("demo").innerHTML = d;
</script>
I need to know the the date when it has last been saved at the file system! And how can i change this 11-9-2014 at 23:7:55 to smth normal September 11 at 23:07?
document.lastModified will give you the time the document was last modified so far as the browser is able to determine it. You won't find anything closer unless you implement some method to embed the time stamp into the file when you save it.
Is this what you are looking for?
document.getElementById("demo").innerHTML = document.lastModified;
Demo here: http://jsfiddle.net/donal/w58v89Lh/
Related
I'm trying to send a table from google sheets to gmail using apps script, i have multiple dates and i want to send in this format "dd-mm-yy", but the problem is that i need to use utilites.formatdate which coverts the cell into string, so when i try to send the email it diplays that the parameters dont match the method, i think this is because in some cells date could be not fullfilled, so theres nothing written in the cell, because of this error i cant send the email, if i write dates in the cells it works but there are cases when they are not fullfilled as i said, how can i solved this problem and send the email no matter if all the dates are filled or not?
var fecha = registro.getRange("c16").getValue();
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");
This is the way i tried to change the format, and if there is someting written works but
var fecha2 = registro.getRange("e16").getValue();
var fecha2F = Utilities.formatDate(fecha2, "GMT","dd-MM-YY");
In the second there is nothing so it displays the error
Hope you can help me guys
I'm learning so all kind of advices you give to me are welcome
Try this:
var fecha = new Date(registro.getRange("c16").getValue());
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");
Try to initiate Date by adding new DATE() to use the converted string as DATE type and after that you can format it as you want
so your code will be
var fecha = new DATE(registro.getRange("c16").getValue());
EDIT
var fechaF = Utilities.formatDate(fecha, "GMT","dd-mm-yyyy").setNumberFormat('dd-mm-yyy');
I'm Attempting to create a Merge between some sheet Data, a doc template and a final doc template.
Mainly, I have access to these files like this:
var contratotemplate = DocumentApp.openById(contratotemplateId);
var contratonovo = DocumentApp.openById(contratonovoId);
var ws = SpreadsheetApp.openById(planilhaId).getSheetByName("Contratos Ref Marca");
Than, used this code to pick each Data from a Range that I want.
var data = ws.getRange(3,1,1,ws.getLastColumn()).getValues();
The Problem is here when I try to replacetext with cell information from my sheet trough another function callback (the one that actually replace text with info):
data.forEach(function(r){
CriarMailMerge(
r[30].getDate()+"/"+r[30].getMonth()+"/"+r[30].getFullYear(),
paragrafosTemplate,
contratonovo);
});
The result is this:
11/5/2019 //in contratonovoId field supposed to have the correct date.
I've already tried .toLocaleDateString()
The result is:
June, 11 2019.
Which solves my problem, but I can't find a way to bring that info into Brazilian Portuguese.
Can u guys help me?
I Used this and worked:
r[30].getDate()+"/"+("0" + (r[30].getMonth() + 1)).slice(-2)+"/"+r[30].getFullYear(),
RESULT
11/06/2019
I am trying to get the time a user goes on a page and save it as a cookie (in JavaScript) I'm able to get the current time but I can't seem to be able to save it as a cookie.
The reason why I'm doing this is because I'd like to know how long it took my class to go from the first page to the last page of my training site. I collect the first time stamp when they load the first page, and I collect the second time stamp when they load the finale page (their are 5 pages).
I'm not sure if there is a better way of doing this with Javascript?
Here is my code: (thanks in advance)
var d = new Date();
document.getElementById("test").innerHTML = d;
docCookies.setItem("time", "test");
<p id="test"></p>
Use following code. This will add your current date in cookie.
var d = new Date();
document.cookie="time="+d;
Try this :-
document.cookie = "name=John Doe; expires=Tue, 01 Aug 2017 12:00:00 UTC";
You can also go for Local Storage to store temporary data
localStorage.setItem("name", "John Doe");
Happy Coding...
I've been learning Ruby over the last year and I'm very new to JS so I'll try to explain this as best I can.
I am using Adam Shaw's full calendar plugin. All I want to do is get the current month I am viewing (and use that to limit how far in the future or past a user can navigate, but that's not the problem).
I can get the current date, sort of. But, because of my lack of JS knowledge I'm not sure how to access the date.
Here is the relevant section of the config file,
viewRender: function(view){
var maxDate = "<%= finish.strftime('%Y/%m/%d') %>";
var currentDate = $('#calendar').fullCalendar('getDate');
console.log(currentDate);
if (view.start > maxDate){
header.disableButton('prev');
}
}
When I inspect the console log I see this being output as I click through the months.
So as you can see it is displaying the current date in view. My question is how do I access the _d bit of the Moment variable so I can use it?
My understanding would be that the Moment is class instance and the stuff in the dropdown is like its attributes, would this be a correct interpretation?
To get the current date of the calendar, do:
var tglCurrent = $('#YourCalendar').fullCalendar('getDate');
This will return the date as a moment object. You can then format it as a string in the usual date format like so:
var tgl=moment(tglCurrent).format('YYYY-MM-DD');
For the actual time, use the format: YYYY-MM-DD LTS
FullCalendar's getDate returns a moment object, so you need moment's toDate() method to get date out of it.
So, in you code try:
console.log(currentDate.toDate());
and that should return a date object.
var moment = $('#YourCalendar').fullCalendar('getDate');
var calDate = moment.format('DD.MM.YYYY HH:mm'); //Here you can format your Date
I want to use client system date on page load event,
How can I do that.
Since this is not a post back so please let me know how to do it.
Thanks
var a = "&date=" + (new Date().replace(/\s+/g, ""));
Just append the value of a to all your links back to the server. On the serverside you will see the datetime come across in the HTTP request.
var currentDate = new Date()
The currentDate object will have the methods:
getMonth()
getDate()
getFullYear()
This should give you what you need.
Edit:
Since you mentioned time in the title of the post, it's probably worth mentioning that currentDate will also have:
getHours()
getMinutes()
should you want to display the current time as well.
Edit 2:
To tie into page loading
<script type="text/javascript">
function buildDate() {
var date = new Date();
/*build date string here*/
}
</script>
<body onload="buildDate()">
Other stuff here...
</body>