how to make date/time field independent of the current time zone - html

Datetime-local depends on the current time zone of the machine. If we want to make it independent of the time zone in date time field what type we should use??

You have to fix a timezone and make it standard.
In python you may use datetime.utcnow()
>>> from datetime import datetime
>>> datetime.utcnow()
datetime.datetime(2017, 4, 21, 6, 28, 11, 61789)

you can use library https://momentjs.com/ which can make your work easier
var newYork = moment.tz("2014-06-01 12:00", "America/New_York");
var losAngeles = newYork.clone().tz("America/Los_Angeles");
var london = newYork.clone().tz("Europe/London");
newYork.format(); // 2014-06-01T12:00:00-04:00
losAngeles.format(); // 2014-06-01T09:00:00-07:00
london.format(); // 2014-06-01T17:00:00+01:00

Related

Highcharts with external CSV $.get - No xAxis date

I'm trying to create a spline chart using this CSV:
slave_id,date,time,rtc_temp,temp1,temp2,temp3
1,2017/12/26,16:42:59,21,11.50,13.13,5.88
2,2017/12/26,16:43:29,21,14.13,20.63,99.99
1,2017/12/26,16:44:00,21,11.50,13.13,5.88
2,2017/12/26,16:44:30,21,14.13,20.63,99.99
1,2017/12/26,16:45:01,21,11.50,13.13,5.88
2,2017/12/26,16:45:31,21,14.13,20.63,99.99
1,2017/12/26,16:46:02,21,11.50,13.13,5.88
2,2017/12/26,16:46:32,21,14.13,20.63,99.99
As you can see here [IMAGE], the graph is showing the date and time, but the x Axis is not accepting the date / time.
Ive tried using date.UTC, but that did not work either. Can someone point me in the right direction?
https://jsfiddle.net/asvoy6b9/ [not working due to CSV missing]
Full code [Hastebin]
I see that date variable in your code is a string:
// all data lines start with a double quote
line = line.split(',');
date = line[1] + " " + line[2];
(...)
RTC.push([
date,
parseInt(line[3], 10)
]);
If you choose to construct the point's options as an array of two values and the first value is a string then it's treated as its name property (not x).
Explanation: https://www.highcharts.com/docs/chart-concepts/series
In that case Highcharts assigns subsequent integers as x values for all points (that's why there're values like 00:00:00.000 (1 Jan 1970), 00:00:00.001 etc.).
You need to parse your date to timestamp. You can use Date.UTC() (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) or some other function for this.
I've managed to get it working with Date.UTC using the following code:
var yyyymmdd = line[2].split("-"); //Split the date: 2017 12 16
var hhmmss = line[3].split(":"); //Split the time: 16 11 14
var date = Date.UTC(yyyymmdd[0], yyyymmdd[1] - 1, yyyymmdd[2], hhmmss[0], hhmmss[1], hhmmss[2]); //Stitch 'em together using Date.UTC

Syntax for defaulting to current time for Google Directions API

I'm trying to parse this URL and I'm wondering if anyone could tell me what to put in for the departure_time parameter so that it defaults to the current time:
https://maps.googleapis.com/maps/api/directions/json?origin=25broadyway&destination=pennstation,ny&departure_time=????current&mode=transit
I've tried:
current, 0, time.now....I can't figure it out
From the Google APIs:https://developers.google.com/maps/documentation/directions/
departure_time specifies the desired time of departure as seconds since midnight, January 1, 1970 UTC*.
Example: http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&key={API_KEY}&departure_time=1343641500&mode=transit
EDIT:
Try something like this method to get your departure_time in seconds:
private static string GoogleMapsDepartureTime(DateTime localTime)
{
DateTime inceptionDateTime = DateTime.Parse("01/01/1970 00:00:00");
DateTime departureDateTime = localTime.ToUniversalTime();
TimeSpan departureTimeSpan = departureDateTime - inceptionDateTime;
double departureTimeSeconds = departureTimeSpan.TotalSeconds;
return departureTimeSeconds.ToString().Split('.')[0];
}
I noticed there was no accepted answer or feedback so I'll take a crack at it. You should write "now" and it will give you the departure time to the nearest second.
Source:
https://developers.google.com/maps/documentation/directions/

Extjs date format issue safari firefox

Dates are stored in the format, YYYY-mm-dd hh:mm:ss in the database.
e.g. 2014-07-03 00:00:00
But I want my Ext.Field.Date to have the format:
Y-m-d H:i
As per my component set up:
xtype: 'datefield',
id: 'p_p_start',
fieldLabel: 'Planned Start',
name: 'plannedstart',
allowBlank: false,
vtypeText: 'Date not valid',
format: 'Y-m-d H:i',
It is quite reasonable of me to want to be able to display the date in browsers other than just Chrome. To-date, FireFox and Safari will display nothing.
I've looked at a similar issue on SO which proposed support of all browser by splitting and reassembling the string format in a variation of:
var c=Ext.getCmp('p_p_start');
var st_date = "2014-05-08";// with alt formats changed Y-m-d, leaving time out diags
var dateParts = st_date.split(/-/);
var d = new Date(dateParts[0],parseInt( dateParts[1], 10) -1,dateParts[2]);
console.log("Date parts= " + dateParts);//Date parts= 2014,05,08
c.setValue( d ); //NOPE!
I was very happy with progress in Chrome (no problems at all) but have yet to succeed in getting anything working in FF or Safari (not tried IE but it has to work in that also). So, in summary, the question is,
How do I get date formats in all browsers to work with the format Y-m-d H:i using setValue?
Many thanks in advance.
Kevin
A date field's internal value is a JavaScript Date Object, which is not tied to a specific format. The format config simply defines the display and input format of the field.
You can use setValue with a string, but only if the string already conforms to your defined format.
In your case the problem seems to be converting a date string value with a different format which was received from the server/database to a Date object.
Have a look at the Ext.Date singleton, specifically its function Ext.Date.parse, to achieve that:
var st_date = "2014-05-08";
var dateObj = Ext.Date.parse(st_date, "Y-m-d");
Ext.getCmp('p_p_start').setValue(dateObj);
var st_date2 = "2014-07-03 00:00:00";
var dateObj2 = Ext.Date.parse(st_date2, "Y-m-d H:i:s");
Ext.getCmp('p_p_start').setValue(dateObj2);

Why is 1401-01-01 a Saturday in Ruby but a Thursday in MySQL?

In Ruby:
> require 'time'
=> true
> Date.new(1401, 1, 1).saturday?
=> true
With MySQL:
SELECT dayofweek('1401-01-01')
This returns 5 which is Thursday.
In the OSX Calendar, this is also a Thursday.
What is causing this discrepancy?
I strongly suspect that one of those environments is taking into account the change from the Julian calendar to the Gregorian calendar (at various times since the 16th century depending on place).
Using my Noda Time library, we can see which is which:
using System;
using NodaTime;
class Test
{
static void Main()
{
var julian = new LocalDate(1401, 1, 1,
CalendarSystem.GetJulianCalendar(4));
var gregorian = new LocalDate(1401, 1, 1,
CalendarSystem.GetGregorianCalendar(4));
Console.WriteLine("Julian: {0}", julian.IsoDayOfWeek);
Console.WriteLine("Gregorian: {1}", gregorian.IsoDayOfWeek);
}
}
Output:
Saturday
Thursday
So it looks like Ruby has taken the transition into account, but MySQL hasn't.
The big question is: which calendar system were you interested in? (In 1401 you probably want the Julian one - but if you have dates in the 16th century or later, it becomes trickier...)

TimeDelta class in ActionScript?

Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.