mktime

Finding days between 2 unix timestamps in php

大兔子大兔子 提交于 2019-11-28 19:13:59
Hay, i have a database holding events. There are 2 fields 'start' and 'end', these contain timestamps. When an admin enters these dates, they only have the ability to set the day,month,year. So we are only dealing with stamps containing days,months,years, not hours,minutes,seconds (hours,minutes and seconds are set to 0,0,0). I have an event with the start time as 1262304000 and the end time as 1262908800. These convert to Jan 1 2010 and Jan 8 2010. How would i get all the days between these timestamps? I want to be able to return Jan 2 2010 (1262390400), Jan 3 2010 (1262476800) .. all the way

How to convert week number and year into unix timestamp?

喜欢而已 提交于 2019-11-28 11:52:49
I'm trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this? I assume you are using ISO 8601 week numbers, and want the first day of a ISO 8601 week so that e.g. Week 1 of 2011 returns January 3 2011 . strtotime can do this out of the box using the {YYYY}W{WW} format: echo date("Y-m-d", strtotime("2011W01")); // 2011-01-03 Note that the week number needs to be two digits. Shamefully, DateTime::createFromFormat , the fancy new PHP 5 way of dealing with dates, seems unable to parse this kind

day18

孤街浪徒 提交于 2019-11-28 09:46:57
1. random模块 1.1 基础方法   import random # (1) 取随机小数: 数学计算 print(random.random()) # 取0-1之间的小数 print(random.uniform(1, 2)) # 取所给范围之间的小数 # (2) 取随机整数: 彩票 抽奖 print(random.randint(1, 2)) # [1,2] 顾头也顾尾 print(random.randrange(1, 2)) # [1,2) 顾头不顾尾 print(random.randrange(1, 200, 2)) # 每两个取一个(200以内的奇数) # (3) 从一个列表中随机抽取值: 抽奖 li = ['a', 'b', (1, 2), 123] print(random.choice(li)) # 随机取一个 print(random.sample(li, 2)) # 随机取两个 # (4) 洗牌 打乱一个列表的顺序(没有返回值,在原来的列表基础上直接进行修改,节省空间) li = ['a', 'b', (1, 2), 123] random.shuffle(li) print(li) 1.2 验证码 - 课上练习 # 随机数练习 # (1) 4位 数字验证码 # (2) 6位 数字验证码 # (3) 6位 数字+字母验证码 # (1) 4位 数字验证码

各种Web脚本下,日历的实现方法

丶灬走出姿态 提交于 2019-11-28 03:43:03
在Web开发中我们经常会需要开发一些和日历相关的应用,自然需要制作一些日历程序,一些大家伙比如C#,JAVA或是VB.NET这些语言以往都有不少文章和示例介绍了,所以今天我给大家说一下其他常见Web脚步语言中的日历算法逻辑和具体的实现方式,希望对大家有用。 先看看我们的实现目标,就是在网页中通过脚本语言实现如下的日历: 要实现日历就必须用到相关语言中的日期和时间函数,其中最重要的是具有下面功能的两个函数: 能返回指定日期是星期几的函数 能返回指定年份和月份一共有多少天的函数,或者可以返回指定两个日期之间相差多少天的函数 只要语言中具有上面两个功能的函数就可以轻松实现日历。 实现日历的算法逻辑大致如下: 取得当前要显示的月份的1号是在星期几 取得当前要显示的月份一共有多少天 通过HTML的方式生成一个HTML的表格来显示日历(每行显示一周,并根据需要来决定是生成5行还是6行的表格) 根据显示的月份1号所在星期几空出前面的不属于该月日期的表格单元格 根据显示的月份1号所在星期几来决定生成表格时从星期几开始生成日历显示(第一天在星期几) 根据一共有多少天来顺次生成指定天数,另外每生成七个单元格需要加入一个表格的换行 补足HTML表格空缺的单元格 剩下的就是根据不同语言中具体的函数来实现了: 下面是根据上述算法和逻辑在asp中的具体实现代码: 1 < style > 2 td { font

In PHP given a month string such as “November” how can I return 11 without using a 12 part switch statement?

余生颓废 提交于 2019-11-28 00:01:59
I.e. Month Returns January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 I've seen examples using mktime when given the number of the month and returning the month string, but not the reverse. Try echo date('n', strtotime('November')); // returns 11 If you have to do this often, you might consider using an array that has these values hardcoded: $months = array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 =>

Curve Fitting to a time series in the format 'datetime'?

浪子不回头ぞ 提交于 2019-11-27 22:57:12
Here is my problem: polyfit does not take datetime values, so that I converted datetime with mktime producing the polynomial fit works z4 = polyfit(d, y, 3) p4 = poly1d(z4) For the plot however, I would like the datetime description on the axis and didn't # figure out how to do that. Can you help me? fig = plt.figure(1) cx= fig.add_subplot(111) xx = linspace(0, d[3], 100) pylab.plot(d, y, '+', xx, p4(xx),'-g') cx.plot(d, y,'+', color= 'b', label='blub') plt.errorbar(d, y, yerr, marker='.', color='k', ecolor='b', markerfacecolor='b', label="series 1", capsize=0, linestyle='') cx.grid() cx.set

Finding days between 2 unix timestamps in php

孤街浪徒 提交于 2019-11-27 12:03:25
问题 Hay, i have a database holding events. There are 2 fields 'start' and 'end', these contain timestamps. When an admin enters these dates, they only have the ability to set the day,month,year. So we are only dealing with stamps containing days,months,years, not hours,minutes,seconds (hours,minutes and seconds are set to 0,0,0). I have an event with the start time as 1262304000 and the end time as 1262908800. These convert to Jan 1 2010 and Jan 8 2010. How would i get all the days between these

How to convert week number and year into unix timestamp?

♀尐吖头ヾ 提交于 2019-11-27 06:33:49
问题 I'm trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this? 回答1: I assume you are using ISO 8601 week numbers, and want the first day of a ISO 8601 week so that e.g. Week 1 of 2011 returns January 3 2011 . strtotime can do this out of the box using the {YYYY}W{WW} format: echo date("Y-m-d", strtotime("2011W01")); // 2011-01-03 Note that the week number needs to be two digits. Shamefully,

In PHP given a month string such as “November” how can I return 11 without using a 12 part switch statement?

守給你的承諾、 提交于 2019-11-26 21:37:26
问题 I.e. Month Returns January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 I've seen examples using mktime when given the number of the month and returning the month string, but not the reverse. 回答1: Try echo date('n', strtotime('November')); // returns 11 If you have to do this often, you might consider using an array that has these values hardcoded: $months = array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 =>

PHP convert date format dd/mm/yyyy => yyyy-mm-dd [duplicate]

五迷三道 提交于 2019-11-26 19:34:21
Possible Duplicate: PHP Date String Format I am trying to convert a date from dd/mm/yyyy => yyyy-mm-dd . I have using the mktime() function and other functions but I cannot seem to make it work. I have managed to explode the original date using '/' as the delimiter but I have no success changing the format and swapping the '/' with a '-' . Any help will be greatly appreciated. Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash ( / ), then the American m/d/y is assumed; whereas if the separator is a dash