簡體   English   中英

我在嘗試將字符串數據分配給 Integer 變量時遇到問題

[英]I am having problem when i am trying to assign String data to Integer variable

String showYear;
  String showMonth;
  String showDay;
  int showDayIntVersion;

  Future getNepaliDate() async {
    NepaliDateTime _selectedDateTime = await picker.showAdaptiveDatePicker(
        context: context,
        initialDate: NepaliDateTime.now(),
        firstDate: NepaliDateTime(2000),
        lastDate: NepaliDateTime.now()
    );
    setState(() {
      showYear = DateFormat("yyyy").format(DateTime.parse(_selectedDateTime.toString()));
      showMonth = DateFormat("MM").format(DateTime.parse(_selectedDateTime.toString()));
      showDay =DateFormat("dd").format(DateTime.parse(_selectedDateTime.toString()));
        showDayIntVersion= int.parse(showDay);
     
    });
  }

#在我的 showYear 中我得到 2022,在 showMonth 中我得到 04,在 showDay 中我得到 02 但是當我將 showDay 分配給 showDayIntVersion 我只得到 2 並且由於它給出了無效的日期格式日 dateTime 格式並且我有理由將 showDay 分配給showDayIntVersion 需要幫助謝謝

如果你想將字符串顯示為 int 然后這樣做:

int.parse(showday);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM