【问题标题】:Reformat Yahoo finance date?重新格式化雅虎财务日期?
【发布时间】:2015-06-16 22:56:22
【问题描述】:

我正在使用http://finance.yahoo.com/d/quotes.csv?s= 获取公司的股票价格并嵌入他们的网站。我有两个问题:

  1. 是否可以重新格式化日期?它目前返回 MM/DD/YYYY,如果我能够重新格式化以返回 DD/MM/YYYY,那就太好了。这可能吗?

  2. 此外,返回的日期带有引号,字面意思是返回“MM/DD/YYY”。我真的很想去掉这些引号。

有什么想法吗?

许多 TIA!


编辑:

我正在使用以下代码:

<?php
$asxcode = 'TDO';
$price = file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=' . $asxcode . '.AX&f=l1');
$date = file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=' . $asxcode . '.AX&f=d1');
echo '$' . $price . '<br/>' . $date;
?>

【问题讨论】:

  • 它有助于提供我们应该查看的实际 URL 和数据。
  • 道歉 - 我原以为这会比现在更容易。
  • 不是很难,而是可能有更好的方法。
  • 只是一个友好的提醒。对雅虎和你的服务器好点,并对这些内容进行缓存。也许几分钟就可以了:)

标签: php yahoo-finance


【解决方案1】:

试试这个:

//get rid of the quotation marks
$yahoo_date = trim($yahoo_date, '"');

//will recognize yahoo's format and convert to a timestamp 
$timestamp = strtotime($yahoo_date); 

//you can now format it in any way you want
$reformatted_date = date('d/m/Y', $timestamp);

【讨论】:

  • 有趣的是,当我尝试这个时,我得到的日期是 01/01/1970!
  • 你有日期吗?当您对它执行var_dump 时(在此代码之前),您会得到什么?
  • 我得到:string(14) ""11/26/2010" "
  • 哦,我明白了,雅虎在日期中返回了一些垃圾。将trim 行替换为:$yahoo_date = trim($yahoo_date, "\"\r\n");
  • 嗯,去掉了引号,但重新格式化仍然不起作用。我在尝试做不可能的事吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-10
  • 1970-01-01
  • 2017-03-01
相关资源
最近更新 更多