I'm working on a single page chat application, and when displaying the message sent by some user ,I want all the other users to see the same exact time the message was sent in and also the correct time regardless user's computer time or any other reason. As I understood UNIX time do the job ,and I want to use it in my app and put it inside datetime HTML attribute . Is there a way to do that in HTML or should I use JS for that?
Note: I think that this question isn't relevant to me because first I want to use the attribute datetime and second thing I want to use Unix time .
Any help is appreciated.Thank you.
Something like this?? You can set the dateTime attribute of the time tag with the date.toISOString function since it is one of the supported formats by the time tag.
var unixTime = 0; // fill in your epoc time here.
var isoTime = new Date(unixTime).toISOString()
timeEl.textContent = unixTime+' --- '+isoTime+' --- '+new Date(isoTime).toString();
timeEl.setAttribute('datetime', isoTime )
<time id="timeEl"></time>
Related
I hate dates, I can never get them to behave.
I have a javascript variable that looks like this:
var currentDate = new Date();
I pass this to a C# Web API controller as a parameter.
My local time was 12:43 but when I put a breakpoint in my action it shows 11:43. The problem is, that if I do this at 00:43 then my controller would take the date as yesterday. I need it to pick out the right day. If I select the currentDate as 02/09/2015 12:43 then I need my controller to use the same date.
I know this has something to do with local times etc, but how can I get them all to use the same one?
Any help would be greatly appreciated.
I am using Adobe XI Standard and have a pdf document with a text field “Today” with a Mouse Up Java script of
var f = this.getField("Today");
f.value = util.printd("mmm/d/yyyy", new Date());
Problem 1) I want this to automatically update when the document opens instead of when the mouse enters it but I dont know how or where to place the script in the proper place.
I have a text field labeled “text11” formatted to be a date mm/dd/yyyy
I have another text field labeled “21stDay” which I want to calculate 21 days from the date in the “text11” field.
Problem 2) I have not been able to get any script to work. Can anyone please tell me how to make this work properly and where to exactly place the scripts as I am just a novice at doing this.
Thank you in advance!
I believe that there are two potential ways to do this:
An OpenAction entry in the Catalog root with an Action dictionary of S(ub)type JavaScript
Named JavaScripts seem to be executed when the document is first opened in Acrobat.
For the fomer see table 3.25 in section 3.6.1 and section 8.5 in the PDF v1.7 Reference, and section 3.6.3 for the latter.
The first thing you can do with a Document-level script containing just that single line:
this.getField("Today").value = util.printd("mmm/d/yyyy", new Date()) ;
If you encounter timing issues (meaning that the field does not get filled reliably, use the PageOpen event of the page on which the document opens. This makes sure that the script is run only when the document is properly loaded.
For the second question, this should work (not I have not verified the code):
var now = new Date() ;
var then = new Date() ;
then.setDate(now.getDate+21) ;
this.getField("text11").value = util.printd("mm/dd/yyyy", then) ;
Note that the Date object is smart enough to properly convert a date number greater than the date of the end of month.
I have to display respective time zone in digital format. The clock is displayed but it only updates after refreshing the page. Below is the code I used.
Below is my javascript code:
time: function() {
var zone = _.date.fleetTimeZone();
return moment().zone(zone).format('h:mm:ss a');
}.property('DS.session.last_fleet_interacted'),
Below is my handlebars:
<div class="time">{{time}}</div>
You'll need to turn time into a property, and update it each second, using setTimeout() or something. Then it'll work because of data binding (I assume Ember.js because tags).
Alternatively, just do a setTimeout() and re-render the time manually.
I want to save the actual date in a variable. only the date, no time
var a = #Date(#Now());
datasource.replaceItemValue("variable", a)`
And
var a = #Date(#Now());
var b = new Date(a.getYear(), a.getMonth(), a.getDay());
datasource.replaceItemValue("variable", b)
Are returning 28.10.14 00:00
var dt:NotesDateTime = #Date(#Now());
datasource.replaceItemValue("variable", dt.getDateOnly());
Is throwing me an error
Isn't there a simple way to get only the actual date without the time?
Use setAnyTime() metohd of NotesDateTime class to remove time component.
If you want to save only the date use a textfield and convert the text to date, if you need it in your code
#Now uses a java.util.Date, which includes time portions. .getDateOnly() is probably throwing an error because that returns a String.
The underlying session.createDateTime() method accepts either text, a java.util.Date or a java.util.Calendar. I think all of them need to include a time element.
If you're only storing the value for reference, I'd agree with brso05 to not worry.
If you're ever likely to use #Adjust (or an equivalent), then not worrying about the time is a recipe for disaster, because every time you try to adjust, you need to remember to take into account Daylight Savings Time.
One option is to set the time to 12:00 midday. That means DST will not be a problem.
java.sql.Date is specifically designed to only include the Date portion, without a time element. Jesse Gallagher talks about java.sql.Date in the context of his frostillic.us framework https://frostillic.us/f.nsf/posts/32A63DD640D868D885257D18006659A9 and he was the one I found out about java.sql.Date from. I'm not sure how he stores those values though.
I'm not sure if the OpenNTF Domino API will allow you to just pass a java.sql.Date to a field and so store just the date portion.
I've been using AnyTime datepicker: http://www.ama3.com/anytime/ and I now need to set the TimeZone and update AnyTime datepicker with javascript. Only I can't seem to find the option to do this, And I'm not exactly a Javascript Hero.
I think I've narrowed it down to the function askOffset: function( event ) on line 1919 But can't exactly figure it out what to do next. I don't know what the abbreviated variables mean and I've been randomly trying things and can't figure it out.
The reason I'm doing this is because I have the select dropdown somewhere else on the screen (looks fancier) and I also want the ability to load the saved timezone from cookies.
I've also found some documentation that might be useful: utcFormatOffsetImposed and utcParseOffsetAssumed on the AnyTime page.
The picker automatically parses the timezone from the value in the input field, so if you want to set a specific timezone, just initialize the input field with a value that uses the same timezone.
utcFormatOffsetImposed and utcParseOffetAssumed can be used to force specific time zone conversion in AnyTime.Converter, so if you want to use the converter to initialize the field, you can do something like this:
<input type="text" id="myField"/>
<script>
$(function(){
var myFormat = '%r %#';
var myConv = new AnyTime.Converter({format:myFormat});
myConv.utcFormatOffsetImposed( -330 );
$('#myField').
AnyTime_picker({format:myFormat}).
val( myConv.format(new Date()) );
});
</script>
Of course, replace the format string with whatever you want, as long as it contains %#, %+, %-, %;, %; or %# for the timezone information.