我为iPhone制作了一个日历应用程序,其中我有一个字符串格式的日期(例如"Tue,2010年5月25日12:53:58 +0000").
我想将其转换为NSDate
.
我需要做什么才能做到这一点?
我已经搜索了stackoverflow的解决方案并发现了这个:
我的问题是,我从SQL-Server-Database中加载了一些数据,并希望在DataGrid中的WPF应用程序中显示它们.这非常有效.我唯一要改变的是日期列的格式为"DD/MM/YYYY HH:MM:SS",我希望有"DD.MM.YYYY".好的,然后我看了下面的链接并在我的程序中尝试了这个:
<Grid Width="648" Height="263">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="172*" />
<ColumnDefinition Width="90*" />
<ColumnDefinition Width="386*" />
</Grid.ColumnDefinitions>
<DataGrid Name="dgBuchung" Height="213" HorizontalAlignment="Left" Margin="30,16,0,0" VerticalAlignment="Top" Width="595" AutoGenerateColumns="True" ItemsSource="{Binding}" Grid.ColumnSpan="3" Foreground="Black" BorderBrush="#FF688CAF" Opacity="1" Background="White" BorderThickness="1" >
<!-- <ab:DataGridTextColumn Header="Fecha Entrada" Width="110"
Binding="{Binding date, StringFormat={}{0:dd/MM/yyyy}}" IsReadOnly="True" />
-->
</DataGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
out评论部分是我的解决方案,但它抛出XMLParseException.首先,使用AutoGenerateColumns时这种解决方案是否可行?如果不是,我怎么能尝试处理这个?如果是,上面的代码有什么问题?
编辑: 我的问题没有解决,因为我决定不重建我的应用程序,没有AutoGenerateColumns = true的解决方案?
如何将以下内容转换为插入/更新到MySQL中的字段TIMESTAMP
或日期DATE
?
'15-Dec-09'
Run Code Online (Sandbox Code Playgroud)
DATE_FORMAT()
用于格式化日期,但不是相反.
我有一个$ i的变量,它是一个shell脚本中的秒,我试图将它转换为24 HOUR HH:MM:SS.壳中有可能吗?
2012年12月1日00:00:00 GMT
我必须将上述日期转换为以下格式
2012年12月1日
我怎么能够?
我试过以下方法,但它没有工作
public Date ConvertDate(Date date){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String s = df.format(date);
String result = s;
try {
date=df.parse(result);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
Run Code Online (Sandbox Code Playgroud) 为了显示可重现的场景,我正在做以下事情
获取当前系统时间(当地时间)
将本地时间转换为UTC //在这里工作正常
反转UTC时间,返回当地时间.遵循3种不同的方法(如下所列),但所有3种方法仅保留UTC时间.
{
long ts = System.currentTimeMillis();
Date localTime = new Date(ts);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat (format);
// Convert Local Time to UTC (Works Fine)
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmtTime = new Date(sdf.format(localTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());
// Reverse Convert UTC Time to Locale time (Doesn't work) Approach 1
sdf.setTimeZone(TimeZone.getDefault());
localTime = new Date(sdf.format(gmtTime));
System.out.println("Local:" + localTime.toString() + "," …
Run Code Online (Sandbox Code Playgroud)java utc simpledateformat date-formatting timestamp-with-timezone
我在跑步时遇到了撞车,它指向了dateFormmater.timezone
.控制台中的错误是:
无法将'Swift.Optional'(0x1192bf4a8)类型的值转换为'NSTimeZone'(0x1192c0270).
价值rowEvents.date
是"1480134638.0"
我试图从Firebase中取出一个Unix时间戳保存为字符串.将其转换为Date并再次将其保存为字符串,以便将其发布到单元格标签上.
我从StackOverflow获得了这段代码.我插入了我的数据,一切都很好,直到我运行它.我想一切都不是很好......
if let lastUpdated : String = rowEvents.date {
let epocTime = TimeInterval(lastUpdated)! / 1000 // convert it from milliseconds dividing it by 1000
let unixTimestamp = NSDate(timeIntervalSince1970: epocTime) //convert unix timestamp to Date
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone() as TimeZone!
dateFormatter.locale = NSLocale.current // NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
dateFormatter.date(from: String(describing: unixTimestamp))
let updatedTimeStamp = unixTimestamp
let cellDate = DateFormatter.localizedString(from: updatedTimeStamp as Date, dateStyle: DateFormatter.Style.full, timeStyle: DateFormatter.Style.medium)
cell.subtitleLabel.text …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用sqlite数据库中的日期.我将我的日期存储为时间戳,但是当我使用strftime()将它们格式化为人类可读日期时,我会得到不可预见的结果.
请考虑以下内容,我选择当前时间戳:
SELECT strftime("%s","now");
1281353727
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用我知道代表的时间戳格式化日期,现在期望获得今天日期的人类可读格式:
SELECT strftime('%d - %m - %Y ', 1281353727);
01 - 04 - 3503
Run Code Online (Sandbox Code Playgroud)
相反,我得到了上述结果.这是正确的行为吗?难道我做错了什么?
提前致谢,
凯文
我最近增加了一个新的模式,我的网站,我使用的是admin.py文件来指定正是我希望它会显示在管理网站.它工作得很好,但我无法弄清楚如何让我的一个日期字段包含其显示格式的秒数.我只看到"2011年8月27日,下午12点12分"这样的价值,我想看的是"2011年8月27日,12:12*:37*pm"
在DateTimeFormatter
类文件说,有关当年的格式代码:
你在2004年; 04
y年的2004年; 04
...
年份:字母数决定了使用填充的最小字段宽度.如果字母数是2,则使用减少的两位数形式.对于打印,这将输出最右边的两位数字.对于解析,这将使用2000的基值进行解析,从而产生2000到2099(包括2000和2099)范围内的一年.如果字母数小于4(但不是2),则符号仅按负号年份输出,符合SignStyle.NORMAL.否则,如果超出了焊盘宽度,则根据SignStyle.EXCEEDS_PAD输出符号.
没有提到"时代".
那么究竟是什么这两个代码之间的差异,u
对y
,year
对year-of-era
?
什么时候应该使用类似这种模式的东西uuuu-MM-dd
以及何时yyyy-MM-dd
使用Java中的日期?
似乎那些知道使用的代码编写的示例代码uuuu
,但为什么呢?
其他格式化类如遗产SimpleDateFormat
只有yyyy
,所以我很困惑为什么java.time uuuu
为"年代" 带来了这个.