本文整理汇总了Python中pytz.gae.pytz.timezone函数的典型用法代码示例。如果您正苦于以下问题:Python timezone函数的具体用法?Python timezone怎么用?Python timezone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:Anenth,项目名称:Invoice-Application,代码行数:7,代码来源:main.py
示例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)
开发者ID:jmvuilla,项目名称:mywindstats,代码行数:33,代码来源:checkweatherdb.py
示例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')
开发者ID:ksachdeva,项目名称:tipfy,代码行数:7,代码来源:test_i18n.py
示例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')
开发者ID:mihaip,项目名称:streamspigot,代码行数:25,代码来源:twitterdisplay.py
示例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")
开发者ID:jbholden,项目名称:cdcpool_google,代码行数:27,代码来源:test_timezone.py
示例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')
开发者ID:aleahmanzi,项目名称:street_art,代码行数:28,代码来源:city-street-art.py
示例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')
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:8,代码来源:extras_i18n_test.py
示例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
开发者ID:dittos,项目名称:LangDev-Links,代码行数:9,代码来源:urls.py
示例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
开发者ID:galuano1,项目名称:twitalkerplus,代码行数:12,代码来源:xmpp.py
示例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)))
开发者ID:godshall,项目名称:django-gae-timezones,代码行数:12,代码来源:utils.py
示例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)
开发者ID:Hubble1,项目名称:eventgrinder,代码行数:25,代码来源:humanize.py
示例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
开发者ID:datacommunitydc,项目名称:eventgrinder,代码行数:35,代码来源:forms.py
示例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)
开发者ID:jivemonkey,项目名称:walking-challenge,代码行数:30,代码来源:main.py
示例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
开发者ID:sportlin,项目名称:newsshow,代码行数:26,代码来源:globalutil.py
示例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
开发者ID:esonderegger,项目名称:Algae-CMS,代码行数:25,代码来源:algaeModels.py
示例16: hello
def hello():
"""Return a friendly HTTP greeting."""
utc_time = datetime.datetime.now(pytz.utc)
local_time = utc_time.astimezone(pytz.timezone("America/Vancouver"))
return render_template(
"index.html",
current_time=local_time.strftime('%A, %Y-%m-%d %I:%M %p'))
开发者ID:studflexmax,项目名称:studflexmax,代码行数:7,代码来源:main.py
示例17: post
def post(self):
SelectedDevice = cgi.escape(self.request.get('device'))
SelectedTime = cgi.escape(self.request.get('time'))
SelectedSignal = cgi.escape(self.request.get('Signal'))
SelectedData = cgi.escape(self.request.get('data'))
SelectedWS = [cgi.escape(self.request.get('slot_ws0')),
cgi.escape(self.request.get('slot_ws1')),
cgi.escape(self.request.get('slot_ws2')),
cgi.escape(self.request.get('slot_ws3')),
cgi.escape(self.request.get('slot_ws4')),
cgi.escape(self.request.get('slot_ws5')),
cgi.escape(self.request.get('slot_ws6')),
cgi.escape(self.request.get('slot_ws7')),
cgi.escape(self.request.get('slot_ws8')),
cgi.escape(self.request.get('slot_ws9'))]
SelectedVolt = cgi.escape(self.request.get('slot_volt'))
SelectedTemp = cgi.escape(self.request.get('slot_temp'))
voltage = int(SelectedVolt)*16
temperature = int(SelectedTemp)*4-300
dtnow = datetime.datetime.now()
utc=pytz.utc
paris=pytz.timezone('Europe/Paris')
for i in range(10):
utc_dt = utc.localize(datetime.datetime.fromtimestamp(int(SelectedTime)))-datetime.timedelta(minutes=9-i)
local_dt=utc_dt.astimezone(paris)
updateday = local_dt.strftime("%Y-%m-%d")
updateheure = local_dt.strftime("%H")
updateminute = local_dt.strftime("%M")
newentity = PortableAnemometer(date=dtnow, vitesse=int(SelectedWS[i]), updateday=updateday, updateheure=updateheure, updateminute=updateminute, voltage=voltage, temperature=temperature)
newentity.put()
开发者ID:jmvuilla,项目名称:mywindstats,代码行数:32,代码来源:getwindspeed.py
示例18: __get_local_timezone
def __get_local_timezone(self):
# TODO: change this code to player's preferred timezone
# TODO: test view page with a different timezone
try:
return self.__timezone
except AttributeError:
return pytz.timezone('US/Eastern')
开发者ID:jbholden,项目名称:cdcpool_google,代码行数:7,代码来源:player_results_page.py
示例19: get
def get(self):
# replace with your credentials from: https://www.twilio.com/user/account
account_sid = appconfig.get_twilio_SID()
auth_token = appconfig.get_twilio_auth_token()
calling_number = appconfig.get_twilio_calling_number()
client = TwilioRestClient(account_sid, auth_token)
# Set timezone to Pacific
tz = pytz.timezone('America/Vancouver')
ancestor_key = ndb.Key("TextMessages", "*all*")
messages = TextMessage.query(TextMessage.post_date == datetime.datetime.now(tz).date(), ancestor=ancestor_key).fetch()
ancestor_key = ndb.Key("TextAddresses", "*all*")
numbers = TextAddress.query(ancestor=ancestor_key).fetch()
numbers_messaged = []
if len(messages) < 3 and len(numbers) < 200:
for message in messages:
for number in numbers:
if number.number not in numbers_messaged:
try:
rv = client.messages.create(to=number.number, from_=calling_number, body=message.content)
self.response.write(str(rv))
numbers_messaged.append(number.number)
except:
logging.info("Failed to send to number " + number.number + ". Probably because of blacklist; safe to ignore.")
开发者ID:kurtisharms,项目名称:ubcexamcram,代码行数:25,代码来源:main.py
示例20: from_ical
def from_ical(ical, timezone=None):
tzinfo = None
if timezone:
try:
tzinfo = pytz.timezone(timezone)
except pytz.UnknownTimeZoneError:
pass
try:
timetuple = (
int(ical[:4]), # year
int(ical[4:6]), # month
int(ical[6:8]), # day
int(ical[9:11]), # hour
int(ical[11:13]), # minute
int(ical[13:15]), # second
)
if tzinfo:
return tzinfo.localize(datetime(*timetuple))
elif not ical[15:]:
return datetime(*timetuple)
elif ical[15:16] == 'Z':
return datetime(tzinfo=pytz.utc, *timetuple)
else:
raise ValueError(ical)
except:
raise ValueError('Wrong datetime format: %s' % ical)
开发者ID:valentinalexeev,项目名称:vaeventcal,代码行数:27,代码来源:prop.py
注:本文中的pytz.gae.pytz.timezone函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论