本文整理汇总了Python中pytz.gae.pytz.timezone函数的典型用法代码示例。如果您正苦于以下问题:Python timezone函数的具体用法?Python timezone怎么用?Python timezone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDateTime
def getDateTime():
d = datetime.datetime.today()
UTC=pytz.timezone('UTC')
india=pytz.timezone('Asia/Kolkata')
dd=UTC.localize(d)
dd=dd.astimezone(india)
return dd
示例2: get
def get(self):
CurrentTime = datetime.datetime.now()
Paris = pytz.timezone('Europe/Paris')
LocalCurrentTime = pytz.timezone('UTC').localize(CurrentTime).astimezone(Paris)
SelectedDate = LocalCurrentTime.strftime("%Y-%m-%d")
SelectedHour = LocalCurrentTime.strftime("%H")
SelectedMinute = LocalCurrentTime.strftime("%M")
qry1 = Weather.query(Weather.updateday == SelectedDate)
qry2 = qry1.filter(Weather.updateheure == SelectedHour)
qry3 = qry2.order(Weather.updateheure,Weather.updateminute)
Samples = [False]*60
for ientity in qry3:
Samples[int(ientity.updateminute)] = True
IntSelectedMinute = int(SelectedMinute)
NumberOfSamples = 0
for I in range(IntSelectedMinute-14,IntSelectedMinute+1):
if (Samples[I]):
NumberOfSamples = NumberOfSamples + 1
# For Lery-Poses, 2 samples every 3mn. This translates into about 10 samples during a 15mn period
if (NumberOfSamples < 8):
EmailBody = "Lery-Poses:\n\tLocal current time = " + LocalCurrentTime.strftime("%Y-%m-%d %H:%M") + "\n\tNumber of samples during the last 15mn: " + str(NumberOfSamples)
mail.send_mail(sender="[email protected]" ,
to="Jean-Michel Vuillamy <[email protected]>",
subject="Weather station data collection issue",
body=EmailBody)
self.response.headers['Content-Type'] = 'text/plain'
self.response.http_status_message(200)
示例3: test_get_timezone_location
def test_get_timezone_location(self):
i18n.set_locale('de_DE')
self.assertEqual(i18n.get_timezone_location(pytz.timezone('America/St_Johns')), u'Kanada (St. John\'s)')
i18n.set_locale('de_DE')
self.assertEqual(i18n.get_timezone_location(pytz.timezone('America/Mexico_City')), u'Mexiko (Mexiko-Stadt)')
i18n.set_locale('de_DE')
self.assertEqual(i18n.get_timezone_location(pytz.timezone('Europe/Berlin')), u'Deutschland')
示例4: get_timezone_for_user
def get_timezone_for_user(user):
if user.time_zone:
try:
timezone_name = _RAILS_TIMEZONE_NAME_TO_TZ_NAME.get(
user.time_zone, user.time_zone)
return pytz.timezone(timezone_name)
except pytz.UnknownTimeZoneError:
logging.info('Unknown timezone name: ' + timezone_name)
pass
if user.utc_offset:
timezone = pytz.FixedOffset(user.utc_offset/60)
# pytz FixedOffset instances return None for dst(), but then
# astimezone() complains, so we just pretend like the DST offset
# is always 0.
timezone.dst = lambda self: datetime.timedelta(0)
return timezone
# Starting in April 2018*, Twitter no longer returns timezone data for users.
# We default to PST since it's more likely to be accurate (at least for
# Mihai) than UTC. The above code thus will never run, but keep it in case
# Twitter changes their mind.
#
# * https://twittercommunity.com/t/upcoming-changes-to-the-developer-platform/104603
return pytz.timezone('America/Los_Angeles')
示例5: test_daylight_time_conversions
def test_daylight_time_conversions(self):
utc = pytz.utc
eastern = pytz.timezone('US/Eastern')
central = pytz.timezone('US/Central')
mountain = pytz.timezone('US/Mountain')
pacific = pytz.timezone('US/Pacific')
london = pytz.timezone('Europe/London')
# assign date to 3/10/2014 7:30 PM eastern
test_date_naive = datetime.datetime(2014,3,10,19,30)
test_date_localized = eastern.localize(test_date_naive)
test_date_utc = test_date_localized.astimezone(utc)
fmt = "%I:%M %p %Z"
date_utc = test_date_utc.astimezone(utc).strftime(fmt)
date_eastern = test_date_utc.astimezone(eastern).strftime(fmt)
date_central = test_date_utc.astimezone(central).strftime(fmt)
date_mountain = test_date_utc.astimezone(mountain).strftime(fmt)
date_pacific = test_date_utc.astimezone(pacific).strftime(fmt)
date_london = test_date_utc.astimezone(london).strftime(fmt)
self.assertEqual(date_utc,"11:30 PM UTC")
self.assertEqual(date_london,"11:30 PM GMT")
self.assertEqual(date_eastern,"07:30 PM EDT")
self.assertEqual(date_central,"06:30 PM CDT")
self.assertEqual(date_mountain,"05:30 PM MDT")
self.assertEqual(date_pacific,"04:30 PM PDT")
示例6: post
def post(self):
data_id = datetime.datetime.now(pytz.timezone(Timezone)).strftime("%Y%m%d%H%M%S")
item = Data_db(id=data_id)
item.data_id = data_id
if users.get_current_user():
data_id = self.request.get('data_id')
if data_id and data_id != '':
item = Data_db.get_by_id(data_id)
else:
data_id = datetime.datetime.now(pytz.timezone(Timezone)).strftime("%Y%m%d%H%M%S")
item = Data_db(id=data_id)
item.data_id = data_id
# - -
item.user_name = users.get_current_user()
item.art_title = self.request.get('art_title')
item.art_about = self.request.get('art_desc')
item.art_latitude = self.request.get('art_latitude')
item.art_longitude = self.request.get('art_longitude')
art_photo = self.request.get('art_photo')
if art_photo:
item.art_photo = images.resize(art_photo, 800, 600)
#
item.put()
time.sleep(1)
self.redirect('/gallery')
示例7: test_get_timezone_location
def test_get_timezone_location(self):
i18n.get_i18n().set_locale('de_DE')
self.assertEqual(i18n.get_timezone_location(pytz.timezone('America/St_Johns')), u'Neufundland-Zeit')
i18n.get_i18n().set_locale('de_DE')
self.assertEqual(
i18n.get_timezone_location(pytz.timezone('America/Mexico_City')), u'Nordamerikanische Inlandzeit')
i18n.get_i18n().set_locale('de_DE')
self.assertEqual(i18n.get_timezone_location(pytz.timezone('Europe/Berlin')), u'Mitteleurop\xe4ische Zeit')
示例8: _get_tz
def _get_tz(tzname=None):
tz = None
try:
tz = pytz.timezone(time_zone_by_country_and_region(geo))
except:
tz = pytz.timezone('Asia/Seoul')
return tz
示例9: func_timezone
def func_timezone(self, args):
length = len(args)
if not length:
return _("CURRENT_TIMEZONE") % self._google_user.timezone
elif length == 1:
try:
pytz.timezone(args[0])
except pytz.UnknownTimeZoneError:
return _("INVALID_TIMEZONE")
self._google_user.timezone = args[0]
return _("SET_TIMEZONE_SUCCESSFULLY")
raise NotImplementedError
示例10: adjust_datetime_to_timezone
def adjust_datetime_to_timezone(value, from_tz, to_tz=None):
"""
Given a ``datetime`` object adjust it according to the from_tz timezone
string into the to_tz timezone string.
"""
if to_tz is None:
to_tz = settings.TIME_ZONE
if value.tzinfo is None:
if not hasattr(from_tz, "localize"):
from_tz = pytz.timezone(smart_str(from_tz))
value = from_tz.localize(value)
return value.astimezone(pytz.timezone(smart_str(to_tz)))
示例11: naturalday
def naturalday(value, arg=None):
"""
For date values that are tomorrow, today or yesterday compared to
present day returns representing string. Otherwise, returns a string
formatted according to settings.DATE_FORMAT.
"""
try:
value = date(value.year, value.month, value.day)
except AttributeError:
# Passed value wasn't a date object
return value
except ValueError:
# Date arguments out of range
return value
site=get_site()
timezone=pytz.timezone(site.timezone)
today=today=utc.localize(datetime.utcnow()).astimezone(timezone).date()
delta = value - today
if delta.days == 0:
return _(u'Today')
elif delta.days == 1:
return _(u'Tomorrow')
elif delta.days == -1:
return _(u'Yesterday')
return defaultfilters.date(value, arg)
示例12: save
def save(self):
site=get_site()
timezone=pytz.timezone(site.timezone)
cleaned_data=self.cleaned_data
profile=get_current_profile()
if profile.userlevel > 9:
credit_name, credit_link= "Staff", None
status='approved'
approved_on=datetime.now()
else:
credit_name, credit_link = profile.nickname, profile.link
status='submitted'
approved_on=None
event=Event(title=cleaned_data.get("title"),
link=cleaned_data.get("link") or None,
description=cleaned_data.get("description")[:250] or None,
start=timezone.localize(datetime.combine(cleaned_data.get("start_date"),cleaned_data.get("start_time"))),
end=timezone.localize(datetime.combine(cleaned_data.get("end_date") or cleaned_data.get("start_date"),cleaned_data.get("end_time"))),
location=cleaned_data.get("location") or None,
submitted_by=get_current_profile(),
status=status,
site=get_site(),
cost=cleaned_data.get("cost"),
credit_name=credit_name,
credit_link=credit_link,
approved_on=approved_on,
approved_by=profile,
)
event.put()
return event
示例13: get
def get(self):
user_vars = self.auth.get_user_by_session()
activities = models.Activity.gql("WHERE ANCESTOR IS :1 order by created", user_vars["user_id"])
tz = pytz.timezone("US/Pacific")
now = datetime.now(tz)
dow = now.weekday()
now = datetime(now.year, now.month, now.day)
start = now - timedelta(days=28 + dow)
end = now + timedelta(days=(6 - dow))
cal = {}
week_total = [0, 0, 0, 0, 0]
week_count = 0
day = 0
for activity in activities:
cal[activity.created] = activity
while start <= end:
if start not in cal:
cal[start] = None
else:
week_total[week_count] += cal[start].count
start = start + timedelta(days=1)
if ((day + 1) % 7) == 0:
week_count += 1
day += 1
self.respond("user_dashboard.html", cal=sorted(cal.iteritems()), today=now, week_total=week_total)
示例14: isBackendsTime
def isBackendsTime():
_INTERVAL_MINUTES = 5
backendsConfig = globalconfig.getBackendsConfig()
if not backendsConfig:
return True
timezonename = backendsConfig.get('timezone')
if not timezonename:
return True
freeHours = backendsConfig.get('hours.free', [])
limitHours = backendsConfig.get('hours.limit', [])
if not freeHours and not limitHours:
return True
nnow = datetime.datetime.now(tz=pytz.utc)
tzdate = nnow.astimezone(pytz.timezone(timezonename))
if tzdate.hour in freeHours:
return True
if tzdate.hour in limitHours and tzdate.minute < _INTERVAL_MINUTES:
return True
return False
示例15: dateTimeString
def dateTimeString(self):
siteTZ = pytz.timezone(algaeUserConfig.siteTimeZone)
localDT = self.postTime.replace(tzinfo=pytz.utc).astimezone(siteTZ)
myDT = ""
myDT += str(localDT.month)
myDT += '/' + str(localDT.day)
myDT += '/' + str(localDT.year)
myDT += ' at '
pm = False
myHour = localDT.hour
if myHour >= 12:
pm = True
myHour -= 12
if myHour == 0:
myHour = 12
myDT += str(myHour)
if len(str(localDT.minute)) == 1:
myDT += ':0' + str(localDT.minute)
else:
myDT += ':' + str(localDT.minute)
if pm:
myDT += ' PM'
else:
myDT += ' AM'
return myDT