小编Gre*_*reg的帖子

Python - 以毫秒为单位的时间差对我不起作用

我已经阅读了一些关于此的帖子,并认为我有一些有用的代码.如果2个值之间的差值小于1秒,则显示的毫秒数是正确的.

如果差异超过一秒,它仍然只显示毫秒的差异.

如下.

正确:

 now_wind 2013-08-25 08:43:04.776209 
 first_time_wind 2013-08-25 08:43:04.506301
 time_diff 0:00:00.269908
 diff 269
Run Code Online (Sandbox Code Playgroud)

错 - 这应该是2000 + 76?:

 now_wind 2013-08-25 08:43:25.660427
 first_time_wind 2013-08-25 08:43:23.583902
 time_diff 0:00:02.076525
 diff 76


 #!/usr/bin/env python
 import datetime
 import time
 from time import sleep
 first_time_wind = datetime.datetime.now()
 sleep (2)
 now_wind = datetime.datetime.now()
 print "now_wind", now_wind
 print "first_time_wind", first_time_wind
 time_diff_wind = (now_wind - first_time_wind)
 print "time_diff", time_diff_wind
 print "diff", time_diff_wind.microseconds / 1000
Run Code Online (Sandbox Code Playgroud)

python

27
推荐指数
5
解决办法
6万
查看次数

Highcharts - 休息 1 小时

我似乎无法弄清楚为什么 x 轴上的时间总是落后一个小时。

我知道它与这条线有关,但我不知道要将其更改为什么。

 date = Date.parse(line[0] + ' UTC');
Run Code Online (Sandbox Code Playgroud)

我当前的时区是伦敦。

我有这个文件:index.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Using Highcharts with PHP and MySQL</title>

<script type="text/javascript" src="js/jquery-1.7.1.min.js" ></script>
<script type="text/javascript" src="js/highcharts.js" ></script>
<script type="text/javascript" src="js/themes/gray.js"></script>

<script type="text/javascript">
    var chart;
                    $(document).ready(function() {
                            var options = {
                                    chart: {
                                            renderTo: 'container',
                                            defaultSeriesType: 'line',
                                            marginRight: 130,
                                            marginBottom: 25
                                    },
                                    title: {
                                  text: 'Temperature for the last hour',
                                            x: -20 //center
                                    },
                                    subtitle: {
                                            text: '',
                                            x: -20
                                    },
                                    xAxis: {
                                            type: 'datetime', …
Run Code Online (Sandbox Code Playgroud)

javascript php highcharts

5
推荐指数
1
解决办法
3134
查看次数

PHPMailer - 此流不支持SSL /加密

我正在尝试让PHPMailer工作并继续收到此错误:

PHP Warning:  stream_socket_enable_crypto(): this stream does not support SSL/crypto in /usr/share/php5/class.smtp.php on line 274
Run Code Online (Sandbox Code Playgroud)

我已经看过一些帖子,人们通过取消注释来修复问题:extension = php_openssl.dll

我做了 - 并重新启动了apache.

有任何想法吗?

这是我正在使用的php示例代码:

在OpenSuse 12.3上运行php 5.3.17和Apache 2.2.22

<?php
require_once('class.phpmailer.php');
include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
// 1 = errors and …
Run Code Online (Sandbox Code Playgroud)

php phpmailer

5
推荐指数
1
解决办法
1万
查看次数

如何获取div文本值?

我有以下html:

<div class="question">
    <div class="text">
          Blah Blah
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我试图使用javascript获得"Blah Blah"的价值.

那样的东西呢?

    alert(document.getElementsByName("question")[0].value);
Run Code Online (Sandbox Code Playgroud)

html javascript

4
推荐指数
2
解决办法
3054
查看次数

下个月用date命令?

我在我的一个脚本中有这个,我相信它已经工作了很长时间.今天下个月的说法是五月?

#date
Mon Mar 31 15:30:13 BST 2014

#date +"%B %Y" --date="+1 month"
May 2014
Run Code Online (Sandbox Code Playgroud)

任何人都知道问题是什么 - 我应该使用更好的"下个月"脚本吗?

bash date

3
推荐指数
1
解决办法
3110
查看次数

为什么这个小C程序没有像预期的那样工作?

我有一个小型的C程序,它利用了difftime.它真的很奇怪,它不会在10秒后打印出来.

但是,如果我取消注释睡眠线,那么它可以工作.

任何想法为什么会这样?

/* difftime example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, struct tm, difftime, time, mktime */

int main ()
{
  time_t start, stop;

start = time(NULL);
        for(; /* some condition that takes forever to meet */;) {
        // do stuff that apparently takes forever.
                stop = time(NULL);
                double diff = difftime(stop, start);
                //sleep (1);
                if (diff >= 10) {
                        printf("10 seconds passed...");
                        start = time(NULL);
                }
        }
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句:代码编译得很好,我在Raspberry Pi上运行它.3.6.11 +#474预防Thu Jun 13 17:14:42 …

c

1
推荐指数
1
解决办法
195
查看次数

在bash scipt中的正则表达式

我有以下文本文件,其中包含:

 12.3-456, test
 test test test
Run Code Online (Sandbox Code Playgroud)

如果该行包含xx.x-xxx,那么我想打印出该行.(X是数字)

我想我有正确的正则表达式并在此测试过:http: //regexr.com/3clu3

然后我在bash脚本中使用它,但是不打印包含文本的行.我搞砸了什么?

#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
    if  [[ $line =~ /\d\d.\d-\d\d\d,/g ]]; then
            echo $line
    fi
done < input.txt
Run Code Online (Sandbox Code Playgroud)

regex bash

1
推荐指数
1
解决办法
59
查看次数

C - 如何将float变量添加到字符串

我有一个包含浮点数的变量,如何将其添加到字符串中呢?

像这样的东西:

int main() {
    char postdata[] = "field1=";
    float mynumber = 123.12;
    postdata = postdata + mynumber;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望最终结果是"field1 = 123.1"

它似乎并不像postdata + mynumber一样容易:(

c

0
推荐指数
1
解决办法
723
查看次数

Linux中的Unicode字符"BLACK DOWN-POINTING TRIANGLE" - CSS?

我正在尝试使用包含黑色向下指向三角形的css文件.在Windows中它工作正常,但只要我将文件复制到Linux服务器,符号就变成垃圾.

我如何在Linux上的css文件中使用此符号.

 content: '.';
Run Code Online (Sandbox Code Playgroud)

点应该是符号.

我试过了:

content: &#9660;
content: '&#9660';
Run Code Online (Sandbox Code Playgroud)

这应该是符号的值,但我猜错了,因为它不起作用.

html css linux

0
推荐指数
1
解决办法
3942
查看次数

文本长度很长时忽略表重量?

我有以下xml布局 - 如果editText_model文本相当短,则表格按重量值分割50/50.

然而,文本得到的时间越长,它就越夸大单词Description.为什么忽略了50/50的分裂?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100">

        <TableRow>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="50"
                android:paddingLeft="5dp"
                android:text="Select"
                android:textSize="15sp"/>

            <RadioGroup
                android:id="@+id/radioGroupAdd"
                android:layout_weight="50"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/RadioModel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Test1"/>

                <RadioButton
                    android:id="@+id/RadioPaint"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="Test2"/>

            </RadioGroup>
        </TableRow>

    </TableLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100">

        <TableRow>
            <TextView
                android:id="@+id/tV_model"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="50"
                android:gravity="center|left"
                android:paddingLeft="5dp"
                android:text="Description"
                android:textSize="15sp"/>

            <EditText
                android:id="@+id/editText_model"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="50"
                android:hint="Enter Description"
                android:inputType="text|textMultiLine|textNoSuggestions"
                android:minLines="3"
                android:text="testing long line of text 1234567890 123 456 77878 89 9 9d"
                android:textSize="15sp"/>


        </TableRow>
    </TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android-linearlayout

0
推荐指数
1
解决办法
213
查看次数

为什么printf四舍五入?

我有一个简单的C程序(在树莓派上编译)应该计算17.67*20(这是353.4)下面的程序打印出353. printf它是否四舍五入?我试过" %g"和" %.1f"

#include <stdio.h>
#include <math.h>

int absolute_humidity(float temp)
{
    float abs_hum = (17.67 * temp);
    return abs_hum;
}

int main()
{
    float abshum = absolute_humidity(20.0);
    printf("%g",abshum);
}
Run Code Online (Sandbox Code Playgroud)

c floating-point printf

-1
推荐指数
1
解决办法
322
查看次数