w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Moment js create datetime in certain timezone
Assuming you are talking about moment-timezone, this does not currently exist in the 0.0.1 release, but has been requested. There is a pending pull request, but it has not yet been merged because there is still some lacking functionality. So you can go try adding that PR manually, or you can wait until it is stable. You might also consider using one of the other time zone libraries instead.

Categories : Javascript

How to intercept timezone of a DateTime object and convert it to another timezone (Ruby/Rails)
You can change the time zone with ActiveSupport's in_time_zone method: email.datetime.in_time_zone(ActiveSupport::TimeZone.new(user.timezone)) I would not rely on the datetimes in the db being in the user's timezone as long as this is not a performance issue. For example, what if the user changes his time zone? You would have to recompute the timestamp for all his emails etc. I recommend changing the zone when displaying an email for now.

Categories : Ruby On Rails

Getting the correct timezone offset in Python using local timezone
According to Wikipedia, the transition to and from Summer Time occurs at 01:00 UTC. At 00:12 UTC you are still in Central European Summer Time (i.e. UTC+02:00), so the local time is 02:12. At 01:12 UTC you are back in the standard Central European Time (i.e. UTC+01:00), so the local time is again 02:12. When changing from Summer Time back to standard time, the local time goes from 02:59 back to 02:00 and the hour repeats itself. So when asking for the UTC offset of 02:12 (local time), the answer could truthfully be either +01:00 or +02:00 - it depends which version of 02:12 you are talking about. On further investigation of the pytz library, I think your problem may be that you shouldn't be using the pytz.reference implementation, which may not deal with these ambiguities very well. Q

Categories : Python

iOS: convert UTC timezone to device local timezone
Time zones can be applied to NSDateFormatter, from which you can generate NSDate variables differentiated by the time difference. NSString* input = @"2013-08-03T05:38:39.590Z"; NSString* format = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; // Set up an NSDateFormatter for UTC time zone NSDateFormatter* formatterUtc = [[NSDateFormatter alloc] init]; [formatterUtc setDateFormat:format]; [formatterUtc setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; // Cast the input string to NSDate NSDate* utcDate = [formatterUtc dateFromString:input]; // Set up an NSDateFormatter for the device's local time zone NSDateFormatter* formatterLocal = [[NSDateFormatter alloc] init]; [formatterLocal setDateFormat:format]; [formatterLocal setTimeZone:[NSTimeZone localTimeZone]]; // Create local NSDate with time zo

Categories : IOS

Can't get php DateTime timezone conversion to work. It doesn't change the time when I change the timezone
You're passing a string to as the second argument, you should pass an int (UNIX timestamp) Try: return date($timeformat, $utctime->getTimeStamp()); Edit: Actually, you could use return $utctime->format("U"); The problem is that you're always returning a new date because you provided a bad argument. You should check your php.ini and display_errors and error_reporting so you can see when php warns you about this things

Categories : PHP

Timezone and datetime php
knowing the current server date such $current = strtotime(date("Y-m-d H:m:s")) //return timestamp can add or subtract hours to result your time to set the current date variable at the user level: $new_time = date($current, strtotime('+5 hours')

Categories : PHP

populating datetime value from php into Jquery Moble text input datetime-local
$(document).ready(function() { $("#datetime-1").val(<?php YOUR CODE ?>); $("#datetime-2").val(<?php YOUR CODE ?>); }); Its a bit hacky but it should work, just make sure the format of the date is what jq mobile is expecting.

Categories : PHP

Parsing a datetime string with timezone in PHP
420 is zone in minutes. 420/60 = 7 I want to parse it so that I can, for example, say what day of the week it is. If you want to know what day of the week it is, you have many options. For example you can use date and mktime-functions: $parsed = date_parse("2013-07-31T19:20:30.45-07:00"); $unix_timestamp = mktime($parsed['hour'], 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], (int)$parsed['is_dst']); echo date('l', $unix_timestamp); So you want to show the information about timezone? You can get the time zone name by using timezone_name_from_abbr function: $name = timezone_name_from_abbr("", -1*$parsed['zone']*60, false); // NB: Offset in seconds! var_dump($name); $timezone = new DateTimezone($name); var_dump($timezone);

Categories : PHP

DateTime is not being saved when TImeZone is set in application.rb
I suspect that "Bern" isn't a valid time zone identifier for Rails, and that that's causing the problem. According to comments on this answer, you can use the following command to see the valid time zone IDs: rails c - ActiveSupport::TimeZone.all.map(&:name) However, I'd strongly recommend against storing timestamps in your local time zone anyway - store them in UTC, and then convert to the local time zone of the user where appropriate. Aside from anything else, this avoids issues around daylight saving transitions.

Categories : Ruby On Rails

Rails issues with timezone on datetime
Sorry, I'm on the tablet so this will have to be brief. I've had a problem like this and corrected it by using something like Time.now.utc I do see that you have in the application.rb config.time_zone though, so this may not work. If it doesn't, here's a good SO answer, maybe it will help Why doesn't `config.time_zone` seem to do anything?

Categories : Mysql

datetime timezone converting cakephp / php
<?php $utc = gmdate("M d Y H:i:s"); // place your gmt timestamp here echo $utc."<br>"; $offset = date('Z'); //gets offset from gmt echo $offset."<br>"; $localtime = strtotime($utc) + $offset; // adjusts to localtime. echo date("M d Y H:i:s", $localtime); ?>

Categories : PHP

How to convert datetime values to right timezone?
As was the case for this question, you shouldn't specify the daylight saving time timezone, just use the normal timezone, the system will understand it is summer time because of the date: as.POSIXct(val, tz="EET", origin = '1970-01-01 00:00:00') [1] "2013-08-14 23:00:10 EEST" "2013-08-14 23:30:12 EEST" "2013-08-15 02:05:11 EEST" "2013-08-15 02:00:11 EEST" "2013-08-15 02:00:11 EEST" NB: I posted this answer because I think it resolves the "unknown timezone" issue. However there is indeed still the issue that it appears as UTC +1 when it should be UTC +3. Using "Europe/Helsinki" gives the same error (at least for me on Mac OS X 10.6 and R 2.14.2, with french locale): as.POSIXct(val, tz="Europe/Helsinki", origin = '1970-01-01 00:00:00') [1] "2013-08-14 23:00:10 EEST" "2013-08-14 23:30:12

Categories : R

How to get DateTime with a UTC datetime and a particular timezone?
I think you need to use DateTimeOffset class. This thread may be helpful. http://msdn.microsoft.com/en-us/library/bb546101.aspx

Categories : C#

timezone aware datetime for django using templates
I just got here accidentally googling for a related problem, but I thought I'd answer, just in case someone finds it as well... What you were after didn't work, because localtime means the local time on the server (expressed in the timezone as defined in your settings). The django app running on the server has no way of figuring out what the client's timezone is. You should detect the timezone in the browser, e.g. using jstz. A more robust solution is to let the users choose their own timezone, but also setting the selection using autodetection (so that most of the time they can just press OK). Then of course you can store this on the server and from that point on, you can generate your templates using the user's timezone: {% loadtz %} {% timezone user.timezone %} ..... {% endtimezone

Categories : Python

Convert datetime to UTC using timezone sometimes works incorrectly
-5 is the base UTC offset, but during Daylight Savings Time that changes by 1 hour to -4. Daylight Saving Time (United States) 2013 began at 2:00 AM on Sunday, March 10 and ends at 2:00 AM on Sunday, November 3 During this time most states move their clocks forward 1 hour (except for example Arizona)

Categories : C#

Joda - Infer timeZone by only having dateTime in format "hh:mm:ss"
If the error margin is not greater than a few minutes, then you can subtract the UTC time from the received local time and round to the nearest hour to get the offset. You can probably use Minutes.minutesBetween, then divide by 60.0 and round. If you're concerned about :30 and :45 time zones, then you can divide by 15.0, round and multiply by 15 to get the offset in minutes. However, once you have the offset, there may not be a unique time zone that uses it. And the list of time zones that correspond to that offset depends on the full date (because of DST). So if you really want the time zone, it is better to have the client send it. Also see difference in seconds between two dates using joda time? and How can I determine a timezone by the UTC offset?

Categories : Java

RoR: Parse datetime UTC string into timezone specific
Try this Time.strptime(item[1], '%Y-%m-%dT%H:%M:%S%z').in_time_zone(Time.zone) Answer to the bonus questions Check the time zone of your db server and double check your rails data (default config / user TZ) use to_formatted_s http://api.rubyonrails.org/classes/Time.html#method-i-to_formatted_s

Categories : Ruby On Rails

Symfony Doctrine query entries by datetime and timezone
You should save the correct timezone for the user in the database and read this: http://docs.doctrine-project.org/en/latest/cookbook/working-with-datetime.html

Categories : Mysql

Converting DateTime from specific timezone to UTC - missing hour?
Yes there is a dalylight saving applied. See Wikipedia Places that use Eastern Standard Time (EST) when observing standard time (autumn/winter) are 5 hours behind Coordinated Universal Time (UTC−05:00). Eastern Daylight Time (EDT), when observing daylight saving time (spring/summer) is 4 hours behind Coordinated Universal Time (UTC−04:00). The conversion method is correct. Your assumption about the EST timezone is flawed. If your input dates are really EST then the conversion is correct. If that does not meet your expectations you need to check from where your input data comes from and in which timezone it was really entered. If you are dealing with saved dates in a database and you do not know anymore what is correct and what not you are in trouble. In general it

Categories : C#

Perl convert date timezone without datetime module
Assuming your local time is already set to GMT-7, simply: use POSIX 'mktime', 'strftime'; my $datetime = '05/26/2013 06:08:00'; my ($month,$day,$year,$hour,$min,$sec) = $datetime =~ m{^([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+):([0-9]+):([0-9]+)z} or die "invalid datetime $datetime "; my $formatted_time = strftime '%e %B %Y %T %Z', gmtime mktime $sec,$min,$hour,$day,$month-1,$year-1900,0,0,0; You may want %d instead of %e and/or %b instead of %B; see http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html and verify that the desired format specifiers are supported on your system.

Categories : Perl

ASP.NET 4.5 OData serialize DateTime to Json missing timezone
After some investigation, I found the problem was not caused by OData. The problem was caused by the DateTime property read by NHibernate from the SQLSERVER database did not contain TimeZone infor, so without this information OData can only generate the date string without TimeZone. Please refer to this link : It gives a very detail explain about NHibernate datetime problem So my solution to this issue is switching from DateTime to DateTimeOffset type both in .NET code and SQLSERVER 2008. Then in database the DateTimeOffset column keep the TimeZone infor and when read by NHiberate it will pass the TimeZone information to .NET DateTimeOffset property. DateTimeOffset was supported from SQLSERVER 2008.

Categories : Json

Conversion from DateTime to Unix Epoch Time in Current Timezone
This is almost certainly the most immediate problem: c.Set(CalendarField.Month, month); My guess is that you're expecting 1 to mean January here - but java.util.Calendar uses 0-based months. You probably want: c.Set(CalendarField.Month, month - 1); There may also be time zone issues, but concentrate on the big ones first - being out by a whole month will almost never be a time zone issue. Alternatively, to get the milliseconds since the unix epoch, you can stick to the .NET types - or even use my Noda Time library. Using just DateTime: private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); static long GetMillisecondsSinceUnixEpoch(int year, int month, int day, int hour, int minute) { DateT

Categories : C#

datetime and timezone conversion with pytz - mind blowing behaviour
The documentation http://pytz.sourceforge.net/ states "Unfortunately using the tzinfo argument of the standard datetime constructors 'does not work' with pytz for many timezones." The code t = datetime( 2013, 5, 11, hour=11, minute=0, tzinfo=pytz.timezone('Europe/Warsaw') ) doesn't work according to this, instead you should use the localize method: t = pytz.timezone('Europe/Warsaw').localize( datetime(2013, 5, 11, hour=11, minute=0))

Categories : Python

How do I handle "out of range" warnings for timezone-aware datetime objects on MySQL with and without SQLAlchemy
Without SQLAlchemy the answer is basically already in the question: Make it naive but in such a way that you always store the same (read: UTC) timezone: if now.tzinfo is not None: now = now.astimezone(utc).replace(tzinfo=None) return now This will make sure that UTC is always stored (but if passing naive make sure that it is always naive! And when pulling the item out of the database, make sure to make it UTC-aware again: if created_at.tzinfo is None: created_at = utc.localize(created_at) return created_at Since MySQL is not capable of tz-aware objects, the check could be removed (it should always be None). For SQLAlchemy, the same approach can be used (but with the extension of letting SA do it automatically). For this we use the TypeDecorator: class TZDateTime(TypeDecorat

Categories : Python

How to get the local timezone of the system from Django?
First of all, you should get timezone of the user or time difference. Example by time difference Firstly, on client side you must get time difference: //JavaScript d = new Date() d.getTimezoneOffset() // print -240 Secondly, time with the different should be converted to timestamp and send to server side. On the serverside from timestamp you can get time that can be saved to database.

Categories : Python

NSDate timeIntervalSinceNow and local timezone?
NSDate represents a single point in time. It does not have (and does not need!!) a time zone. So "a known futureDate (which is in GMT/UTC)" or "I can't supply an NSDate with a correct timezone" does not make sense. [futureDate timeIntervalSinceNow] returns the time interval between futureDate and the current date and time and is completely independent of any time zones. If you do not get the expected result, then perhaps your calculation of futureDate was wrong.

Categories : Objective C

Have C# code run in a different timezone to local time
The usual way would be to store the dates in the database as UTC date times. You can retrieve the UTC date using DateTime.UtcNow. And when you want to use the local time you would use DateTime.Now This MSDN page explains the DateTime structure in more depth DateTime Structure

Categories : C#

Facebook ignores timezone info for non-logged in users on uploaded events with ISO-8601 datetime
Have you enabled time zone support in the Facebook app settings? You can read about this more here.

Categories : Facebook

Parse YYYY-MM-DD dates using the local timezone
Date.parse behaves as follows: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.4.2 The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats. http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 Extended Format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ Z is the time zone offset specified as “Z” (for UTC) or either “+” or “-” followed by a time expression HH:mm The value of an absent time zone offs

Categories : Javascript

UILocalNotification always setting the date to local timezone
The date you pass in in GMT, which in you case is does not match your local time zone. So when you set the date to 17:00 your time corrects it to you timezone (CET) which is GMT+1. Thus an hour gets added to you date. A solution is to set the UILocalNotification timezone to GMT: localNotification.timeZone = [NSTimeZone timeZoneWithName@"GMT"]; From the Apple documentation: The date specified in fireDate is interpreted according to the value of this property. If you specify nil (the default), the fire date is interpreted as an absolute GMT time, which is suitable for cases such as countdown timers. If you assign a valid NSTimeZone object to this property, the fire date is interpreted as a wall-clock time that is automatically adjusted when there are changes in time zones

Categories : IOS

php get local time by timezone code/digit (+1, +2 etc)
I would suggest to look into DateTime class and supported timezones in php.

Categories : PHP

Getting a local date/time for a specific timezone in SQL Server
You do have an ambiguity problem here, but it's not a chicken and egg issue. The piece of information you are missing is, "what defines a day?" I know, it sounds crazy, but a "day" is not a universal concept. It's a local one. For just a minute, put aside issues of time zones, DST and UTC. If I ask you, "How many hours are we apart from 8 AM right now?" You could give me two different answers. It's 7PM right now, so you might say "11 hours" - since that's how much time we are from 8 AM today. But I could also have said "13 hours" - since that's how much time we are from 8 AM tomorrow. Now in this very simplistic sample, you could disambiguate in one of two different ways. You might say "the last 8AM" or "the next 8AM". Or you might say "whichever happened today." Now go back to

Categories : Sql Server

Convert date in one timezone to another timezone using timezone abbreviations
Here you go: // calculate local time in a different city given the city's UTC offset function calcTime(city, offset) { // create Date object for current location var date = new Date(); // convert to msec // add local time zone offset // get UTC time in msec var utc = date.getTime() + (date.getTimezoneOffset() * 60000); // create new Date object for different city // using supplied offset var newDate = new Date(utc + (3600000 * offset)); // return time as a string return "The local time in " + city + " is " + newDate.toLocaleString(); } // get Bombay time console.log(calcTime('Bombay', '+5.5')); // get Singapore time console.log(calcTime('Singapore', '+8')); // get London time console.log(calcTime('London', '+1'));

Categories : Javascript

How to let Newtonsoft.Json allow Json DateTime conversion with Timezone info?
I think this link should help you with setting up MVC3 project working with Newtonsoft Json Serializer. For ISO date time formatter you should change the following lines in the JsonNetResult constructor. public JsonNetResult() { Formatting = Formatting.None; var settings = new JsonSerializerSettings(); settings.Converters.Add(new IsoDateTimeConverter()); SerializerSettings = settings; JsonRequestBehavior = JsonRequestBehavior.DenyGet; } You have to derive your controllers from BaseController to use the custom result. hope this helps.

Categories : Json

Setting up local ip over wireless network to create a local server on Ubuntu
Just add this to your normal runserver command: python manage.py runserver 0.0.0.0:8000 Then others on your local network can access it through: http://192.168.1.18:8000

Categories : Django

Convert datetime to local python
you can use the useful dateutil package and the pytz one for exemple convert to paris timezone from dateutil import parser import pytz FR = pytz.timezone('Europe/Paris') # there is the summer offset changing in this zone date = parser.parse("2013-08-23T23:37:38+0000") datefr = date.astimezone(FR)

Categories : Python

Storing Utc and Local datetime in Mongo
This is the way I force MongoDB to store the raw value, and ignore the DateTimeKind attribute in DateTime object. This may not apply to your business logic, but make sense for us for our particular reasons. BsonSerializer.RegisterSerializer(typeof(DateTime), new MyMongoDBDateTimeSerializer()); public class MyMongoDBDateTimeSerializer : DateTimeSerializer { // MongoDB returns datetime as DateTimeKind.Utc, which cann't be used in our timezone conversion logic // We overwrite it to be DateTimeKind.Unspecified public override object Deserialize(MongoDB.Bson.IO.BsonReader bsonReader, System.Type nominalType, MongoDB.Bson.Serialization.IBsonSerializationOptions options) { var obj = base.Deserialize(bsonReader, nominalType, options); var dt = (DateTime) obj;

Categories : C#

Reset datetime-local by Jquery
I think it not possible to change the date format of HTML5 input type=“date”. On a quick research I found out this SO question is some what similar to yours. Since you have tagged jQuery why don't you use the the Datepicker of jQuery UI. Where it is quite easy to deal with formats.

Categories : Jquery

Get local datetime formate In Jquery
You can change date format in jquery datepicker as such: var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val(); This Link , Link and Link may be helpful.

Categories : Javascript

Java convert UTC timestamp to local DateTime
You can try this String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss a z" ; final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String dateTimeString = sdf.format(new Date()); System.out.println(dateTimeString); // current UTC time long timeStamp=sdf.parse(dateTimeString).getTime(); //current UTC time in milisec Calendar cal = Calendar.getInstance(); cal.setTime(new Date(timeStamp)); cal.add(Calendar.HOUR_OF_DAY, 5); cal.add(Calendar.MINUTE, 30); System.out.println(sdf.format(cal.getTime())); // time relevant to UTC+5.30

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.