I have a flatpickr datetime picker where I can select a date and time in 24 hour clock format. It works fine on desktop, but on mobile it puts a 12 hour AM/PM time selector in. I can disable the mobile version but it is harder to push the up and down arrows to increment the time. Is there a way to tell the mobile version to use a 12 hour time selector?
flatpickr('.timereported', {
enableTime: true,
dateFormat: "Y-m-d H:i",
time_24hr: true,
minuteIncrement: 1,
});
Related
I am using PostgreSQL in my application. Simply I have declared a particular model attribute as sale_date and have set its data type to Date as follows:
//definition in backend model
sale_date: {
type: Sequelize.DATE,
allowNull: true,
}
And I am using moment on the frontend which is on react. I am giving the user a calendar option to select a date and setting the time as 00:00:00 so that the DB does not pick the local time. However, one issue I am facing is that it automatically adds +05 to the time which is the timezone I am currently in.
2021-06-01 05:00:00+05
Here because of +05, the time became 05:00:00 automatically, how to avoid this, I need time to stay 12am always so that the calendar date does not change even if I upload a document at 11:00 pm.
Using moment like this on the frontend
//From front-end implementation
sale_date = moment
.utc(object.sale_date)
.format("YYYY-MM-DD 00:00:00Z");
How do I achieve the desired behavior?
I think that .utcOffset() can be helpful for your case.
const date = moment().format();
const date2 = moment
.utc(date)
.utcOffset(0)
.format();
console.log(date);
console.log(date2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Documentation of utf offset
I don't really understand why this is happening but in mongodb atlas personalisation settings I have set my time zone to the country I am in. I am hosting the frontend on Netlify and I am using Heroku for my node.js backend.
In my schema I have the date set up like so:
requiredDate: {
type: Date,
required: true,
},
On the frontend there is a date picker. If someone was to select a Friday, it always saves in the database as Thursday like below. So, it is always a day behind it would seem, either in hours or days or whatever it is.
2020-08-27T22:00:00.000+00:00
The date picker field on the frontend sends the date to node.js like so:
27/8/2020
I tried this which seems to work but isn't there a more global way of doing it than having to do this for every form that has a date in it?
let localTime = visitDate.toLocaleString("en-US", {
timeZone: "Asia/Calcutta",
});
Is there a way to obtain the local timezone from the system (eg:- ubuntu) using nodejs?
I used moment.js to extract the date and time values. But couldn't find a way to extract the timezone as well.
The existing answers will tell you the current timezone offset, but you will have issues if you are comparing historic/future points in time as this will not cater for daylight saving changes.
In many timezones, the offset varies throughout the year and these changes occur at different dates or not at all depending on the latitude. If you only have UTC time and an offset, you can never be sure what the offset will be in that location at various other times during the year.
For example, a UTC+2:00 offset could refer to Barcelona in the summer or Ivory Coast all year round. The 2hr offset will always display the correct time in Ivory Coast but will be 1hr out for half the year in Barcelona.
Check out this great article covering the above.
How do we cater for all these time zone issues? Well, it's pretty simple:
Save all times in UTC
Store the time zone string for where this event occurred
In modern browsers or node.js, you can get the local IANA time zone string like this:
Intl.DateTimeFormat().resolvedOptions().timeZone // eg. 'America/Chicago'
You can then use this timezone string in a library like Luxon to help offset your captured UTC times.
DateTime.fromISO("2017-05-15T09:10:23", { zone: "Europe/Paris" });
It is very simple.
var x = new Date();
var offset= -x.getTimezoneOffset();
console.log((offset>=0?"+":"")+parseInt(offset/60)+":"+String(offset%60).padStart(2, "0"))
And there is nothing else or you can see if momentJS can help you or not.
Note: This answer is outdated, you can suggest to add in it.
It is this easy, no libraries needed:
console.log("test ...")
let d = new Date()
console.log("UTC time " + d)
let ank = d.toLocaleString('en-US', { timeZone: 'America/Anchorage' });
console.log("your time zone " + ank)
How to see the exact time zone names on most servers:
ls /usr/share/zoneinfo
Works flawlessly:
You'll get the correct time-text regardless of daylight savings issues, etc etc.
Handy related mysql tip:
On almost all servers, mysql also needs to know the tz info.
Basically the solution is, on the shell
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql mysql
.. google more about it.
I solved this using moment.js (http://momentjs.com/docs/)
var moment = require('moment');
var offset = moment().utcOffset();
console.log(''.concat(offset < 0 ? "-" : "+",moment(''.concat(Math.abs(offset/60),Math.abs(offset%60) < 10 ? "0" : "",Math.abs(offset%60)),"hmm").format("HH:mm")));
------Edited--------
I found a better solution using moment.js. Just use moment().format('Z')
which gives the output :
+05:30
I'm looking into the National Weather Service's API and trying to get the temperature per hour for the certain location in the next 24 hours.
I'm using the test client to generate the requests:
http://graphical.weather.gov/xml/SOAP_server/ndfdXML.htm
Input
From: 2015-06-29T15:00:00
To: 2015-06-30T15:00:00
Product: Time series
Variables: Hourly temperatures, Dewpoint temperature, Apparent temperature
Unit: US standard
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p3h-n9-1</layout-key>
<start-valid-time>2015-06-29T17:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-29T20:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-29T23:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T02:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T05:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T08:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T11:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T14:00:00-04:00</start-valid-time>
<start-valid-time>2015-06-30T17:00:00-04:00</start-valid-time>
</time-layout>
<parameters applicable-location="point1">
<temperature type="hourly" units="Fahrenheit" time-layout="k-p3h-n9-1">
<name>Temperature</name>
<value>83</value>
<value>79</value>
<value>72</value>
<value>70</value>
<value>69</value>
<value>74</value>
<value>82</value>
<value>87</value>
<value>87</value>
</temperature>
<temperature type="dew point" units="Fahrenheit" time-layout="k-p3h-n9-1">
<name>Dew Point Temperature</name>
<value>56</value>
<value>59</value>
<value>61</value>
<value>63</value>
<value>64</value>
<value>67</value>
<value>68</value>
<value>68</value>
<value>67</value>
</temperature>
<temperature type="apparent" units="Fahrenheit" time-layout="k-p3h-n9-1">
<name>Apparent Temperature</name>
<value>82</value>
<value>79</value>
<value>72</value>
<value>70</value>
<value>69</value>
<value>74</value>
<value>85</value>
<value>91</value>
<value>90</value>
</temperature>
The temperatures displayed are in 3hour periods. I figured to change the period parameter to 'Weather at a glance'. Indeed I got a time period of 24 hours, but the only parameter displayed in that period was 'Hazards'.
Obviously, each parameter is tied to a time period, but is it possible to get temperature in a 1hour time period instead of 3hour somehow?
If you are open for json then there are plenty of ways to do it.
I would recommend one service named apixu.com. They offer hour by hour weather and they also have a libraries in different programming languages.
https://github.com/apixu?tab=repositories
Indeed there is a NWS web service that displays data per hour. Just took some time to find it.
http://forecast.weather.gov/MapClick.php?lat=42.357700&lon=-71.060500&FcstType=digitalDWML
I have a Windows Service that runs on my
Texas origin Server Central Time.
This will check for all active reminders and compares the reminder time that user wants and send out reminder if it matches with user required time.
Scenarios
User is from EST
User set up a reminder for *1:25 PM * using UI via my website
On submit, my C# business logic converts this time to UTC before storing in my database. That will become '18:25:00'
My Business logic will pull all Active reminders from DB
And checks for reminder time if current UTC time and Reminder setup time diffrence is less then 5 mins, then it will send notification to that customer.
this is how my logic written
DateTime CurrentDate = DateTime.Now.ToUniversalTime();
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
if (Reminder.DailyReminders.Any(x => currentTime.Subtract(x.ReminderTime).TotalMinutes < 5
&& currentTime.Subtract(x.ReminderTime).TotalMinutes > 0))
{
if (Reminder.ReminderMedhodID.Equals(1))
_email.ComposeEmail(Reminder);
}
My Problem is
*currentTime* is always 1 hour behind to user requested reminder time SO my reminders are going out 1 hour late.
Note : currentTime is from below
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
I am not sure if this is the best way to handle this requirement. considering this is one of the way, can any on help how to fix this issue?
Thanks to peter's answer
Can any one help me how to take user input time with Daylight consideration
This what i have so far
public TimeSpan ConvertToUTCTime(string dateStr)
{
DateTime localDateTime = DateTime.Parse(dateStr); // Local .NET timeZone.
DateTime utcDateTime = localDateTime.ToUniversalTime();
string clTimeZoneKey = TimeZone.CurrentTimeZone.StandardName;
TimeZoneInfo clTimeZone = TimeZoneInfo.FindSystemTimeZoneById(clTimeZoneKey);
DateTime clDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, clTimeZone);
if (clTimeZone.IsDaylightSavingTime(localDateTime))
{
// Get DayLight local time in UTC
// Yet to be implemented
}
return clDateTime.TimeOfDay;
}
I got this worked using this
http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx
Ummm...we are currently using Daylight Saving Time in most of the U.S. (though there are some portions of Indiana that did/do use EST?) Since EDT is one hour ahead of EST, your logic is correct. It is the input (EST) that is incorrect.