我想计算给定两个日期之间的所有星期日.我试过以下代码.如果天数较少,但如果我输入更多天,它可以正常工作.它保持处理和最大执行时间超过我改变了时间,但它甚至保持处理甚至执行时间是200秒.
代码是
<?php
$one="2013-01-01";
$two="2013-02-30";
$no=0;
for($i=$one;$i<=$two;$i++)
{
$day=date("N",strtotime($i));
if($day==7)
{
$no++;
}
}
echo $no;
?>
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我正在制作迷你图条形图.到现在为止我能够绘制一个简单的条形图,这里是Jquery代码:
values = [0,8, 15, 10, 50, 25, 35, 70];
$('.sparkline').sparkline(values, {
type: 'bar',
height: '200px',
barWidth: 20,
barSpacing: 10,
barColor: '#56aaff',
zeroColor: '#000000',
enableTagOptions: true,
tagValuesAttribute: 'data-values',
colorMap: ["red", "green", "blue", "yellow", "orange", "#f2f2f2", "maroon", "pink"]
});
Run Code Online (Sandbox Code Playgroud)
HTML
<p>
<span class="sparkline">Loading...</span>
</p>
Run Code Online (Sandbox Code Playgroud)
请参考JSFIDDLE的代码.
现在我想在每个栏上添加图例名称和y轴值,如下所示.

sun,mon,tue是图例,条形顶部白色的值是y轴值.
但我无法实现它.
任何帮助,将不胜感激.
我试图编写一个逃避日文字符的JavaScript方法.
var esc_str=escape("????????•?????");
var dec_str=decodeURIComponent(esc_str);
//%u30C1%u30E3%u30A4%u30CA%u30E2%u30D0%u30A4%u30EB%u2022%u30EA%u30DF%u30C6%u30C3%u30C9 is dec_str as per debugger- console log.
console.log(dec_str);
Run Code Online (Sandbox Code Playgroud)
在解码时,我收到以下错误:
未捕获的URIError:URI格式错误
我们如何逃避日本人物,将其正确解码?
任何帮助表示赞赏!
我mongoDb使用弹性搜索创建了一个映射来索引我的集合。这是mapping属性:
"properties" : {
"address_components" : {
"properties" : {
"_id" : {
"type" : "string"
},
"subLocality1" : {
"type" : "string",
"index" : "not_analyzed"
},
"subLocality2" : {
"type" : "string",
"index" : "not_analyzed"
},
"subLocality3" : {
"type" : "string",
"index" : "not_analyzed"
},
"city" : {
"type" : "string",
"index" : "not_analyzed"
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想从这些字段中检索整体独特的项目:subLocality1, subLocality2, subLocality3, city。此外,每个distinct值都应包含q为一个子字符串。不同的项目还应包含相应的city值。
例子:
"address_components" : …Run Code Online (Sandbox Code Playgroud) 做YouTube上的孩子提供搜索的API,将只返回的YouTube视频的孩子?
我可以使用现有的YouTube api来列出/搜索 YouTube 儿童视频吗?Youtube-kids 应用程序仅提供适合儿童的内容。我可以使用现有的 api 来列出/搜索这些内容吗?
尝试搜索,但没有找到任何东西。
我正在浏览一篇关于在2D游戏中创建Lightning效果的博客.我想在python中实现相同的功能.但是我被困在一个地方.
假设startpoint和endPoint是2D平面中的坐标,表示线段的极值点.
让我们从博客中查看以下代码片段:
midPoint = Average(startpoint, endPoint);
// Offset the midpoint by a random amount along the normal.
midPoint += Perpendicular(Normalize(endPoint-startPoint))*RandomFloat(-offsetAmount,offsetAmount);
Run Code Online (Sandbox Code Playgroud)
.
Normalize(endPoint-startPoint):
Run Code Online (Sandbox Code Playgroud)
该行从startPoint到endPoint获得单位向量(长度为1的向量)
Perpendicular(Normalize(endPoint-startPoint))
Run Code Online (Sandbox Code Playgroud)
然后获得一个垂直于该矢量的矢量(即与线成直角)
我不是一个普通的python编码器.在python中是否有任何内置的Normalize和Perpendicular函数可以帮助我在python中实现上面的代码.
如何检查一个字符串是否包含字符以外:
字母(大写/大写)
数字
空间
逗号(,)
句点(。)
支架( )
和
'
$
+(加号)minus(-)(*)(=)算术运算符
在ColdFusion中使用正则表达式?
我想确保一个字符串甚至不包含指定字符以外的单个字符。
我是用Perl工作的日期时间模块,我不知道我将如何计算 First,Second,Third,Fourth和Last Sunday's,Monday's,... Saturday's指定月份.
我的方法:
从i = 1 ... DateTime-> last_day_of_month(...)运行循环.
指定日期i到日期($ dt)并使用$ dt-> day_of_week()获取星期几.
使用计数器跟踪第一,第二,第三,第四,最后.
如果星期几匹配所需的日期并且计数器匹配所需的间隔,则打破循环.
你能建议比上面更好(或更短)的方法吗?任何帮助表示赞赏.
我正在开发JAVA swing中的应用程序,因为我想要与当前日期的日期差异,就像今天16/04/2013那样它应该返回15/04/2013.我试过以下代码:
Calendar cal = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal.roll(Calendar.DAY_OF_YEAR, -1);
//if within the first 30 days, need to roll the year as well
if(cal.after(cal2)){
cal.roll(Calendar.YEAR, -1);
}
System.out.println("Year " + cal.get(Calendar.YEAR));
System.out.println("Month " + cal.get(Calendar.MONTH));
System.out.println("Day " + cal.get(Calendar.DAY_OF_MONTH));
Run Code Online (Sandbox Code Playgroud)
在这段代码中我期待得到一天的回复日期.但相反,我得到了一个月的约会.防爆.如果今天是16/04/2013,预期的产量是15/04/2013,但我得到15/03/2013(一天一个月回来)作为输出.
我在LCM上解决了以下问题:计算N个模数为1000000007的LCM
我的方法:
typedef unsigned long long ull;
const ull mod=1000000007;
ull A[10009];
/*Euclidean GCD*/
ull gcd(ull a,ull b)
{
while( b != 0)
{
ull t = b;
b= a %t;
a = t;
}
return a;
}
ull lcm(ull a, ull b)
{
return (a/gcd(a,b))%mod*(b%mod);
}
ull lcms(int l ,ull * A)
{
int i;
ull result;
result = 1;
for (i = 0; i < l; i++)
result = lcm(result, A[i])%1000000007;
return result;
}
int main()
{ …Run Code Online (Sandbox Code Playgroud) 我编写了一个简单的Perl程序(Driver.pl),它传递array by reference并调用子程序add in calculate.pmmodule.
calculate.pm模块将两个值100和500推入数组.
当我在Driver.pl文件中打印数组时,它什么都不打印.
Driver.Pl文件:
use calculate;
our @my_array;
sub init() {
$x = 1;
calculate::add($x, /@my_array);
}
init();
for (@my_array) {
print $_; #Prints Nothing.
}
Run Code Online (Sandbox Code Playgroud)
sub add() {
my ($x, @arr) = @_;
push (@arr, 100);
push (@arr, 200);
}
1;
Run Code Online (Sandbox Code Playgroud) 我正在学习Perl Objects.我在模块文件create_schedules.pm中写了一个简单的构造函数:
#!/usr/bin/perl -w
#
package create_schedules;
use strict;
use warnings;
use diagnostics;
sub new {
my $class = shift;
my %params = @_;
my $self=bless{
_para1=>$params{'mypara1'},
_para2=>$params{'mypara2'}
},$class;
return $self;
}
1;
Run Code Online (Sandbox Code Playgroud)
我正在主文件main.pl中创建一个对象:
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use lib::my_module;
sub _start(){
print "Main Function Started\n";
create_schedules::new(
'mypara1' => 'This is mypara1',
'mypara2' => 'This is mypara2',
);
}
_start();
Run Code Online (Sandbox Code Playgroud)
一旦我运行main.pl,我得到以下错误:
Main Function Started
Odd number of elements in hash assignment at …Run Code Online (Sandbox Code Playgroud) perl ×3
algorithm ×1
arrays ×1
c++ ×1
coldfusion ×1
coldfusion-8 ×1
date ×1
datetime ×1
java ×1
javascript ×1
jquery ×1
lcm ×1
php ×1
plot ×1
python ×1
python-2.7 ×1
regex ×1
sparklines ×1
time ×1
youtube ×1
youtube-api ×1