我正在编写 VBA 来导出 xml。我使用 SAXXMLReader 因为我需要非常缩进的输出。
这就是我希望声明的样子:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
结果如下:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
Run Code Online (Sandbox Code Playgroud)
为什么 SAX 忽略我的编码选择以及如何强制它使用 8.
Sub XML_Format_Indent_Save(xmlDoc1 As MSXML2.DOMDocument60, strOutputFile As String)
Dim xmlWriter As MSXML2.MXXMLWriter60
Dim strWhole As String
Set xmlWriter = CreateObject("MSXML2.MXXMLWriter")
xmlWriter.omitXMLDeclaration = False
xmlWriter.Indent = True
xmlWriter.Encoding = "utf-8"
With CreateObject("MSXML2.SAXXMLReader")
Set .contentHandler = xmlWriter
.putProperty "http://xml.org/sax/properties/lexical-handler", xmlWriter
.Parse xmlDoc1
End With
strWhole = xmlWriter.output
ExportStringToTextFile strOutputFile, strWhole
End Sub
Run Code Online (Sandbox Code Playgroud) 如何在 perl 中转换 1461241125.31307。我试过:
use Date::Parse;
$unix_timestamp = '1461241125.31307';
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($unix_timestamp);
$mon += 1;
$year += 1900;
$unix_timestamp_normal = "$year-$mon-$mday $hour:$min:$sec";
Run Code Online (Sandbox Code Playgroud)
结果:(2016-4-21 5:18:45没有填充小时)
我如何填充它并使其成为格林威治标准时间。我要结果说2016-04-21 12:18:45
谢谢大家的回答。
use DateTime;
$unix_timestamp = '1461241125.31307';
my $dt = DateTime->from_epoch(epoch => $unix_timestamp);
print $dt->strftime('%Y-%m-%d %H:%M:%S'),"\n";
Run Code Online (Sandbox Code Playgroud)