小编Tii*_*iJ7的帖子

Java中阿拉伯语和常规日期的日期解析问题

我有一个日期转换器功能,如:

public static LocalDate getLocalDateFromString(String dateString) {
    DecimalStyle defaultDecimalStyle = DateTimeFormatter.ISO_LOCAL_DATE.getDecimalStyle();
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE.withDecimalStyle(defaultDecimalStyle.withZeroDigit('\u0660'));
    LocalDate date = LocalDate.parse(dateString, dateTimeFormatter);
    return date;
}
Run Code Online (Sandbox Code Playgroud)

它适用于阿拉伯日期,例如????-??-??,但是当我传递正常日期时2019-07-31,则抛出异常,因为格式器的类型不同:

Exception in thread "main" java.time.format.DateTimeParseException: Text '2019-07-31' could not be parsed at index 0
Run Code Online (Sandbox Code Playgroud)

我无法控制传递的日期,因为它是由用户传递的。

如何使用相同的函数解析两个日期?

java date

5
推荐指数
1
解决办法
148
查看次数

“withContext”是否创建一个新的协程?

我有以下代码:

import kotlinx.coroutines.*

fun main() = runBlocking {
    launch {
        println("in sub coroutine ${Thread.currentThread().name}")
    }
    println("before coroutine in main ${Thread.currentThread().name}")
    withContext(Dispatchers.IO) {
        println("hello from coroutine ${Thread.currentThread().name}")
        delay(1500)
        println("hello from coutoutine after delay ${Thread.currentThread().name}")
    }
    println("after coroutine in main ${Thread.currentThread().name}")
}
Run Code Online (Sandbox Code Playgroud)

输出是:

import kotlinx.coroutines.*

fun main() = runBlocking {
    launch {
        println("in sub coroutine ${Thread.currentThread().name}")
    }
    println("before coroutine in main ${Thread.currentThread().name}")
    withContext(Dispatchers.IO) {
        println("hello from coroutine ${Thread.currentThread().name}")
        delay(1500)
        println("hello from coutoutine after delay ${Thread.currentThread().name}")
    }
    println("after coroutine in main ${Thread.currentThread().name}")
} …
Run Code Online (Sandbox Code Playgroud)

coroutine kotlin

4
推荐指数
1
解决办法
1665
查看次数

如何通过使用lua从数组中获取所有值

我有一个多维数组:

result = {
  {
    data = {
      language = "English",
      name = "Freak Out",
      list = {
        {
          type = "songs",
          album = "1234"
        }, {
          type = "songs",
          album = "4234"
        }, {
          type = "songs",
          album = "5829"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如何动态访问此数组中的列表?

此代码正在打印第一张相册(1234):

for i, v in pairs(result) do print(v.data.list[1].album) end
Run Code Online (Sandbox Code Playgroud)

我想album用它们打印所有的type。我该怎么做呢?

lua lua-table

1
推荐指数
1
解决办法
358
查看次数

如何使用for循环按降序排列值

我在下拉框中显示年份列表。年份从2017年到当前年份。目前,这些值显示在我的下拉列表中,从2017年开始,一直到今年。但是我希望这些值以降序显示,当前年份(2019)在顶部,然后是2018,最后是2017。

这是我当前的代码:

<?php
for ($i=2017; $i < date("Y")+1; $i++) { 
?>
  <option value="<?php echo$i?>" <?php if($_POST['master_year']== $i) {echo 'selected';} ?>><?= $i;?></option>
<?php 
}
?>
Run Code Online (Sandbox Code Playgroud)

我该如何更改以降序显示它们?

php

0
推荐指数
1
解决办法
35
查看次数

标签 统计

coroutine ×1

date ×1

java ×1

kotlin ×1

lua ×1

lua-table ×1

php ×1