我正在尝试将ISO转换为datetime使用以下代码:
dt = datetime.datetime.strptime("2013-07-23T15:10:59.342107+01:00",
"%Y-%m-%dT%H:%M:%S.%f%z")
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S.%f%z'
Run Code Online (Sandbox Code Playgroud)
将格式上面的ISO字符串转换为对象的最佳方法是什么datetime?我使用的是Python 2.7.6版.
我希望将ISO时间格式转换为yyyy-mm-dd hh:mm:ss.SSS.但是我无法实现转换.我刚接触猪,我试图编写一个udf来处理从ISO格式到yyyy-mm-dd hh:mm:ss.SSS的转换.
请指导我,我尝试了猪的内置功能(FORMAT,DATE_FORMAT)但是无法将数据转换为所需的格式.
当前数据格式:2013-08-22T13:23:18.226220 + 01:00
所需数据格式:2013-08-22 13:23:18.226
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.EvalFunc;
import org.joda.time.DateTime;
import org.joda.time.format.*;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
public class test extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String)input.get(0);
DateFormat dt = new SimpleDateFormat ("yyyy-mm-dd hh:mm:ss.SSS");
Date d_t = dt.parse(time);
String timedt = getTimedt(d_t);
return timedt;
} catch (ParseException …Run Code Online (Sandbox Code Playgroud)