在SQL中格式化指定格式的日期

时间:2015-07-10 12:15:11

标签: sql oracle datetime

我收到了特定格式的特定日期 2015-06-13T21:49:13.395-07:00在数据库中作为varchar插入。

我想将此日期转换为DATE格式,但我没有为同一个

获取正确的格式化程序

2 个答案:

答案 0 :(得分:5)

使用to_timestamp_tz()函数将字符串转换为时区数据类型的时间戳值:

select to_timestamp_tz('2015-06-13T21:49:13.395-07:00'
                      , 'yyyy-mm-dd"T"hh24:mi:ss.ffTZH:TZM') as res
  from dual

结果:

RES                              
----------------------------------
13.06.15 21:49:13,395000000 -07:00

答案 1 :(得分:0)

layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <android.support.v4.view.ViewPager
                android:id="@+id/content1"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@android:color/darker_gray"
                android:orientation="vertical" />


    <android.support.v4.view.ViewPager
                android:id="@+id/content2"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="#ff0000"
                android:orientation="vertical" />
</LinearLayout>

activity:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpage01);
        int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
        ViewPager content = (ViewPager) findViewById(R.id.content2);
        content.getLayoutParams().height = screenHeight - 200 * 2;
        content.requestLayout();
    }