English 中文(简体)
简单 日期 格式只有时间
原标题:SimpleDateFormat get only the time

当我只想从一个时局获得时间时,我就有一个问题。

时间表的一个例子是:

2012-04-19T23:0+ 50200

I think the format is "yyyy-MM-dd T HH:mm:ss.SSSZ" right? And it must be "HH:mm".

我使用以下法典,但只剩以下几条:

public String getTime(String Vertrektijd){
        final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd T HH:mm:ss.SSSZ");
        Date dateObj;
        String newDateStr = null;
        try
        {
            dateObj = df.parse(Vertrektijd);
            SimpleDateFormat fd = new SimpleDateFormat("HH:mm");
            newDateStr = fd.format(dateObj);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
        return newDateStr;
    }

得到帮助!

最佳回答

页: 1

例如,你在问题(即“2012-04-19T23:0 5+0200”)中给出的时间是失踪的Milliseconds。

转交

getTime("2012-04-19T23:05:00.235+0200");

It should work.

Edit: As MH mentioned, If you dont want to use milliseconds you can change the code to

final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd T HH:mm:ssZ");
问题回答

日期有“主人”和“智者”职能,但时间已作解释。 适当方式是使用日历

Calendar calendar = Calendar.getInstance();
calendar.setTime( dateObj );
int hours = calendar.get( Calendar.HOUR_OF_DAY );
int minutes = calendar.get( Calendar.MINUTE );

Here是试图总结 Java和Andin提供的与日期、时间和时间区有关的所有混淆课程。 基本上,你使用哥里安卡伦堡物体的多数日/时间操纵,可能使用日历超级阶级的方法。 为了进行针对当地的格式安排,你需要一个日期。 但是,这只能是日期目标,因此,你需要将日历/格雷戈亚日历改为首期。 基本上,简单的表格是按您已经发现的那样,采用定制格式。

Note there are two different classes called “DateFormat”.





相关问题
Change the date format in kibana

I am working for my internship on the implementation of the ElasticSearch family (ElasticSearch+ Kibana+ logstash). Here is my question: I have a field "@ timestamp" with the following format: 2014-05-...

Quickly getting to YYYY-mm-dd HH:MM:SS in Perl

When writing Perl scripts I frequently find the need to obtain the current time represented as a string formatted as YYYY-mm-dd HH:MM:SS (say 2009-11-29 14:28:29). In doing this I find myself taking ...

Sorting by unknown column type in mysql

So I ve got a users table; storing things like username, email, etc. I then have a user_settings table. Instead of standard columns like timestamp_logged_in, profile_views, etc., I have it organized ...

timestamp date today

Hi guys could you please help me with this. I know it is silly but can t find unswer anywhere: I have a query that shows events from the today time_stamp but I want to include today as well. How do I ...

connection time zone issue with jOra eclipse plugin

I started using the jOra eclipse plugin. The plugin seems pretty robust and I m hoping to stop using SQLDeveloper for 95% of my database needs. Many of our tables have columns of type TIMESTAMP ...

How to get a UNIVERSAL Windows batch file timestamp

I m having trouble generating a timestamp in a Windows batch file, because I get diferent date formats on different Windows versions. My machine: >echo %date% >Tue 11/17/2009 Friends machine: ...

热门标签