English 中文(简体)
通用XML自统一电子签名
原标题:Generate XML dates since the Unix Epoch

I would like to generate an XML file with every third date up to a given date (for example, 10th of June) since the Unix Epoch, at 3pm GMT. Like:

<timestamps>
    <timestamp time="1246000000" text="2011-06-10 15:00:00" />
</timestamps>

Thank you! I need it in PHP!

最佳回答

如果不能彻底理解你的问题,那么,这里就有一些法典产生了我猜想你的希望。 Send in a timestamp (seconds since epoch).

<?php

function generateXML($end_time){
    $three_days = 3 * 24 * 3600;

    echo "<timestamps>
";
    for ($stamp = 15 * 60 * 60; $stamp < $end_time; $stamp += $three_days){
        $text = date( Y-m-d H:i:s , $stamp);
        echo "<timestamp time="$stamp" text="$text" />
";
    }
    echo "</timestamps>";
}

# up to now: 
generateXML(time());
?>
问题回答

#!/usr/bin/python
import time
unixtime, datestring = 15 * 60 * 60,   
while datestring <  2011-06-10 15:00:00 :
 datestring = time.strftime( %Y-%m-%d %H:%M:%S , time.gmtime(unixtime))
 print  <timestamps> 
 print      <timestamp time="%s" text="%s" />  % (unixtime, datestring)
 print  </timestamps> 
 unixtime += (60 * 60 * 24 * 3)

下面是该法典(我可以稍微加以改进,但乌可以提出想法)。

import java.util.*;
import java.lang.*;

class Main
{
        public static void main (String[] args) throws java.lang.Exception
        {
        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
java.text.SimpleDateFormat sdf = 
      new java.text.SimpleDateFormat(DATE_FORMAT);

                Calendar c=Calendar.getInstance();
                c.setTimeInMillis(0);//reset to epoch
                System.out.println(c.getTime());

                Date d=new Date(1970,6,10);
                Calendar inputDate=Calendar.getInstance();
                inputDate.setTime(d);

                while(c.before(inputDate))
                {
                c.add(Calendar.DATE,3);
                System.out.println(sdf.format(c.getTime()));
                }

        }
}

Sampleî here





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签