我想从2018-01-23T12:38:07.439Z到12:38:07更改moment.js的时间选择器的输入格式

时间:2018-01-23 13:03:33

标签: angularjs django angularjs-directive momentjs angular-moment

我使用 angular js material 作为模板,使用 angular js 作为js。因为 angular material js 中没有时间选择器,我使用 moment.js 的时间选择器我使用 Django 作为后端。我通过rest api将数据放入数据库中我的角度模板的代码在这里:

<md-input-container flex-gt-sm class="md-block">
        <label>Opening Time</label>
        <md-icon md-svg-src="/cityaplfreelisting/media/time.svg" class="mdicon"></md-icon>
        <input required  mdc-datetime-picker date="false" time="true" type="text" short-time="true"
               show-todays-date click-outside-to-close="true"
               auto-ok="true"
               min-date="minDate" minute-steps="1"
               format="hh:mm a"
               ng-change="vm.saveChange()"
               ng-model="data.openingTime ">
     </md-input-container> 

实际上我的数据库在 hh:mm:ss formar中通过rest api获取 openingTime 的值,这就是为什么我要更改其显示的时间的输入格式 2018-01-23T12:38:07.439Z 的格式,我的 django型号无法接受

这是我的django模型

from django.db import models
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres.fields import ArrayField
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.text import slugify
from multiselectfield import MultiSelectField


class Shop(models.Model):


    city = models.ForeignKey(City, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)  # will change on_dlt method soon
    subCategory = models.ManyToManyField(SubCategory)
    filterTags = models.ManyToManyField(FilterTag, blank=True)
    owner = models.ForeignKey(settings.AUTH_USER_MODEL,default=1)

    slug = models.SlugField(unique=True, blank=True)
    shopName = models.CharField(max_length=250)
    tagline = models.CharField(blank=True, max_length=500)


    bannerImage = models.ImageField(upload_to=upload_location,
                                    default='shop/defaultimage/default.png',
                                    width_field='widthField',
                                    height_field='heightField')
    widthField = models.IntegerField(default=0)
    heightField = models.IntegerField(default=0)

    likes = models.PositiveIntegerField(default=0)
    dislikes = models.PositiveIntegerField(default=0)
    email = models.EmailField(blank=True)
    mobileNo = models.CharField(max_length=14)
    alternateMobileNo = models.CharField(max_length=15, blank=True)
    location = gis_models.PointField(u'longitude/latitude',
            geography=True, blank=True, null=True)


    ownerName = models.CharField(blank=True,max_length=250)
    shopAddress = models.TextField()
    shopPinCode = models.PositiveIntegerField()



    openingTime = models.TimeField()
    closingTime = models.TimeField()
    closingDay = MultiSelectField(choices=DAYS,default=DAYS[7][0])


    isActive = models.BooleanField(default=0)
    updatedAt = models.DateTimeField(auto_now=True)
    timestamp = models.DateTimeField(auto_now_add=True)

    gis = gis_models.GeoManager()
    objects = models.Manager()

    def __str__(self):
        return self.shopName 

Here is the picture of my time picker

This is picture of json format of openingTime which I am putting through rset api

my django admin (only lower part

请告诉我应该做什么,制作时间输入字段的可接受输入时间格式

1 个答案:

答案 0 :(得分:-1)

您必须更改数据库时域的格式。您无法更改输入时间格式