我做了一个时钟,我正在尝试更新它,以便显示时间.当我启动NSDate时,它是启动时间的精确当前时间的实例.所以我在这里发现的是使用NSTimer ping updateTime函数以每3秒更新一次时钟.
似乎应该有办法更好地做到这一点?我担心通过这种方法我需要使用更多的资源,虽然性能对于时钟来说并不是真正的问题,但我希望在我的资源管理方面做得更好.
我有一个java.sql.Timestamp,我想切断日期并以12小时的方式显示它,例如(18:42 as 6:42 PM)
我试过了:
public static String formatTimestampAsTwelveHour(java.sql.Timestamp stamp){
String stampString = stamp.toString();
String hms = stampString.split(" ")[1];
String[] hmsArray = hms.split(":");
int hours = Integer.parseInt(hmsArray[0]);
int minutes = Integer.parseInt(hmsArray[1]);
int seconds = Integer.parseInt(hmsArray[2]);//just in case someone wants seconds
String suffix = "";
if (hours > 12){
hours = hours -12;
suffix = "PM";
}else if (hours == 12){
suffix = "PM";
}else{
suffix = "AM";
}
String lessThanTen = "";
if (minutes<10){
lessThanTen = "0";
}
return String.format("%i:%s%i …Run Code Online (Sandbox Code Playgroud) 你如何让一个jQuery 只活时钟自动加载并开始移动,这种结构?:
小时:分钟:秒
两列各用分号分隔,并且还有通用或不通用选项(ei 6'o'clock vs. 18'o'clock).它旁边会有一个按钮,可以来回切换"更改显示"或其他内容
在程序的顶部和末尾,我使用clock()来计算程序完成所需的时间.不幸的是,它的报告时间似乎只有一半.我用"time"命令仔细检查了这一点.
我的计划报告:在45.86s完成
时间命令报告:实际0m22.837s用户0m45.735s sys 0m0.152s
使用我的手机定时,它在23秒完成(又名:"真实"时间)."用户"时间是所有线程的总和,因为我使用的是OpenMP.(你可以在这里阅读:'真实','用户'和'sys'在时间(1)的输出中是什么意思?)
那么,为什么clock()报告的是"用户"时间而不是"真实"时间?我应该使用不同的函数来计算程序运行的时间吗?
作为旁注,Windows的clock()按预期工作,并在"实际"时间内报告.
我是VHDL的新手.我得到了关于如何从24 MHz的输入时钟信号产生1Hz(50%占空比)的时钟信号的代码.我有一些问题需要进一步澄清.
如果我想将占空比改为80%,应如何调整代码?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity clock is
port ( CLKin: in std_logic;
reset: in std_logic;
CLKout: out std_logic);
end clock;
architecture arch of clock is
signal counter: integer:=0;
signal temp : std_logic := '1';
begin
process(CLKin,counter,reset)
begin
if(reset='0') then counter<=0; temp<='1';
elsif(CLKin'event and CLKin='1') then counter <=counter+1;
if (counter = 12000000) then temp <= NOT temp; counter<=0;
end if;
end if;
CLKout <= temp;
end process;
end arch;
Run Code Online (Sandbox Code Playgroud)我做了一个圆圈作为我们的玩家并设定了重力,但它的工作速度更快,我甚至看不到.我认为它必须用sf :: time或sf :: clock做一些事情但是怎么做?我实际上没有得到这两个,所以任何代码示例和解释将不胜感激.这是我的代码: -
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
sf::CircleShape shape(20);
shape.setFillColor(sf::Color::White);
shape.setPosition(380, 550);
shape.setOutlineColor(sf::Color::Green);
shape.setOutlineThickness(3);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
shape.move(0, -100);
}
if(event.KeyReleased)
{
if(event.key.code == sf::Keyboard::Up)
{
int x[] = { 10, 10, 10, 10, 10};
for (int y = 0; y <= 4; y++)
{
shape.move(0, x[y]);
}
}
}
}
window.clear(sf::Color::Black);
window.draw(shape);
window.display();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我用PHP获得GMT时间,我想像时钟一样计算它.
<?php $time = gmdate('H:i:s'); ?>
<script>var time = <?php echo($time) ?>;
setInterval(function() {
time += 1;
$("#timediv").text("Current time (GMT): " + time);
//somehow convert it to 11:44:31 AM ??
}, 1000);
</script>
Run Code Online (Sandbox Code Playgroud)
可以帮助我吗?
我正在使用clock()C中的函数来获取秒数,但是通过这个小测试程序,我发现我的处理器没有正确计算滴答,因为秒太多与实时不同步,另外我不得不将结果乘以100得到更接近秒的东西,但我认为它没有意义.在这个程序中,10s几乎相当于现实生活中的7s.有人能帮助我clock()更精确地成为这个功能吗?
我正在使用Beaglebone Black rev C,内核为3.8.13-bone70,Debian为4.6.3-14,gcc为4.6.3
提前致谢!
这是我的测试程序:
#include <stdio.h>
#include <time.h>
int main(){
while(1)
printf("\n%f", (double)100*clock()/CLOCKS_PER_SEC);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我在Qt中调用了argon2 - 内存密集型散列函数并测量其运行时间:
...
QTime start = QTime::currentTime();
// call hashing function
QTime finish = QTime::currentTime();
time = start.msecsTo(finish) / 1000.0;
...
Run Code Online (Sandbox Code Playgroud)
在argon2库的测试用例中,时间以另一种方式测量:
...
clock_t start = clock();
// call hashing function
clock_t finish = clock();
time = ((double)finish - start) / CLOCKS_PER_SEC;
...
Run Code Online (Sandbox Code Playgroud)
我正在调用它们在测试用例中调用的函数.但我的数字增加了两倍(两倍慢).为什么?如何测量Qt中的函数运行时间?clock()实际测量的是什么?
env:virtualBox,Ubuntu14.04 64bit,Qt5.2.1,Qt Creator 3.0.1.
我写了一个程序,每隔五秒就会在十秒钟的时间内打印一个随机数(1-10).但它似乎每五秒打印一个以上的随机数.有人能指出我正确的方向吗?
clock_t start;
int random;
start = clock();
while (float(clock() - start) / CLOCKS_PER_SEC <= 10.0) {
if (fmod(float(clock() - start) / CLOCKS_PER_SEC, 5) == 0 && (float(clock() - start) / CLOCKS_PER_SEC) != 0) {
random = rand() % 10 + 1;
cout << random << endl;
}
}
return 0;
Run Code Online (Sandbox Code Playgroud)